Volume calculation from grouped solids


#1

Hi

I have cases where it is organized geometry into groups, hence I know that is is possible to calculate the volumn from. The sketchup api allows volumn computation from component. So my thought was to at export from sketchup, copy these geometries to a compnent, calculate the voumn and then delete the component, hence obtaining the volumn but not exporting a component, which should not be a component. I am well aware this is a hack and I hope upon a function which could be working upon group level instead in the future.

My question is: Is there any easy functions which allows copy of entities or faces directly to the component instance? Something like

SUComponentInstanceAddEntities(&suComponentInstanceRef, entities);
or
SUComponentInstancesAddFaces(&suComponentInstanceRef , facerefs[]);

And then after using the componentInstance for volumn computation, I can do a release upon the component, without effecting the rest of the data?

HowToCalculateVolumeFromThis.skp (101.8 KB)


#2

That is the very difficult way of doing this. There is much simpler way.

a. In SketchUp, a group is a special type of component instance, so both have a component definition.
b. To access functions of the SUComponentInstance class, cast the group to a componentinstance.
c. Then call the SUComponentInstanceComputeVolume() function

See this topic thread …

… and this C API feature request …

https://github.com/SketchUp/api-issue-tracker/issues/90

NO. Groups are an instance (a special subclass of component instance just as Image is.) Instances do not have entities collections, their definitions own the collection.


#3

I tried your solution and it worked upon cases where it was one group with a solid under it, but not in cases where it was a group with a group and then solid. This could be related to the bug which I reported in which I was importing groups to sketchup.

To import a group to sketchup I need to do the following:
SUGroupRef suSpatialType = SU_INVALID;
SU_CALL(SUGroupCreate(&suSpatialType));
SU_CALL(SUGroupSetName(suSpatialType, spatialTypeTag.c_str()));
SU_CALL(SUEntitiesAddGroup(entities, suSpatialType));

There is no transformation matrix involved hence, I do not set it since it is identity.

Is this the correct way to importing a group in Sketchup?


#4

Currently there is no way to copy entities. If you try to add entities from one collection to another collection you will eventually crash as both claim ownership of the entities passed in. (No copy is being made.)

I don’t quite understand what you mean here. What Dan suggests, using SUGroupToComponentInstance to get a SUComponentInstanceReffrom aSUGroupRef`. The nesting level should be irrelevant.

This might be easier if you can provide a small complete code snippet and a test model to illustrate the issue you are describing.

There should be no need to copy entities around just to get the volume information from a component or group. But you need to make sure that you call SUComponentInstanceComputeVolume on the inner most instance that contains the faces and edges that makes up the manifold.