Rhino.MeshVolume


#1

I am new to scripting.

I found a script on a forum. It compiles data from a Rhino file and exports it to excel. I have used it successfully but altered the script to calculate the volume of a mesh.

I’m not sure what I’ve done wrong. The result of the mesh calculation is always 1. I’ve tried it on multiple files but it always returns 1 as the result. If I run the volume tool on the object within rhino, I get an accurate volume.

I’m attaching the script. Hopefully someone can help.

Thanks,
J

volumeproblem.txt (1.9 KB)


#2

MeshVolume returns an array of 3 values, not a single value. The value at index 1 is what you want.

So the line

xlApp.Cells(intCount + 2, 7).Value = Rhino.MeshVolume(strobject)

should read

xlApp.Cells(intCount + 2, 7).Value = Rhino.MeshVolume(strobject)(1)

You will have the same problem with SurfaceVolume…

So, you would need

`xlApp.Cells(intCount + 2, 8).Value = Rhino.SurfaceVolume(strobject)(0)

However, if either the mesh or surface volume calculations fail, the script will error out, as there is no error checking…

—Mitch


#3

Hi Mitch,

Thank you very much for your reply.

I made the changes and just as you indicated, the script failed after reading one mesh and trying to calculate the next object which was a polysurface.

The error is Line 67 and says Type Mismatch

Is the script causing an error because its trying to get a volume on a polysurface using the mesh.volume tool?

I’ve made numerous attempts trying to assign the appropriate geometry to the appropriate tool. I’ve attached my attempts. You will see some attempts in green have been disabled.

Thanks again.
J

volumeproblem.txt (3.3 KB)


#4

Hi again Mitch,

I think I figured it out. Im attaching the updated script in case others are learning from the thread.

Thanks again for your help. I am amazed by the generosity of the forum members.

J

volumeproblem.txt (2.6 KB)