Model's volume using ruby api

hello everyone i was working on a code to calculate volume of a 3D model:

model = Sketchup.active_model
group=model.entities.add_group(Sketchup.active_model.entities.to_a)
if (group)
vol=group.volume/61024

UI.messagebox vol.round(2) 

array = group.explode
group=model.entities.fill_from_mesh(array)

else
UI.messagebox “Failure”
end

but it worked on the model “A” and it gave correct value but it didn’t work on the “B” model it gives 0.0 as volume value.
Does anyone have an idea why it doesn’t work for the “B” model ?

thnx a lot in advance.

Model A is a Manifold Solid.

Model B is NOT a Manifold Solid.

If the separate ‘cubes’ in B were grouped as individual Manifold Solids, then you can get their individual volumes.

BUT if you have them ALL in the same context, then you will see that three of the Edges within the common geometry are ‘shared’ by two ‘cubes’ each.

So then it cannot ever be a Manifold Solid !
So it cannot have a ‘volume’…

To recap what has been said many times before…
A Solid can only contain Edges and Faces.
Every Edge must support exactly TWO faces.
In your failing example there are three edges that have four faces - NOT two !

1 Like

thnx for your answer now i understand it.
but how can i get the volume for such a model, the B one ? as i need to calculate the volume of the entire model even if it has the shape of the “B” model ?

Because it is not a solid it cannot have a meaningful volume.

Separate the boxes into separate solid cubes and then get their volumes - then add them together ?
Alternatively make sure they don’t have a common edge - even a 0.1mm gap will do !

If you look at my old volume tool, here:
http://sketchucation.com/pluginstore?listtype=1&author=0&category=0&search=volumecalc&submit=%3F
that cuts a series of horizontal faces though the selected group and then makes a summation of these to give an approximated volume…
In your illustrated case the volume should be pretty accurate…