Volume moments of inertia of several bodies in Rhino using Python?

Hey everybody,
.
.
I have a problem writing a plug-in for Rhino using Python.
.
I have several closed bodies, no open edges, and I would like to get the volume moments of inertia.
.
In Rhino, there is a command called “VolumeMoments”: I can select all my bodies and get the moments of inertia as a result in an extra window.
.
Using Python, I found the command “SurfaceVolumeMoments”.
If I use this command for one body, I get the right values.
… but if I try to select two or more bodies, it says:
.
.
.
Message: Parameter must be a Guid or string representing a Guid
.
Traceback:
line 468, in coerceguid, “C:\Users\pk\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\utility.py”
line 547, in coercesurface, “C:\Users\pk\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\utility.py”
line 1468, in __GetMassProperties, “C:\Users\pk\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\surface.py”
line 1524, in __AreaMomentsHelper, “C:\Users\pk\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\surface.py”
line 1931, in SurfaceVolumeMoments, “C:\Users\pk\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\surface.py”
line 17, in , “C:\Users\pk\AppData\Roaming\McNeel\Rhinoceros\5.0\scripts\test.py”
.
.
.
My commands are:
.
obj = rs.GetObjects(‘Bitte Volumenkoerper waehlen: ‘)
.
VM = rs.SurfaceVolumeMoments(obj)
print’VOLUMENTRAEGHEITSMOMENTE im Verhaeltnis zu den Koordinatenachsen des Mittelpunkts:’, VM[10]
print’ Fehlerschranke:’, VM[11]
.
.
.
Can perhaps anybody help me?
I added some pictures of the ten bodies for you to get an impression what I mean :smiley:
.
Thanks a lot!
Phil
.
.
.

.

.

I’m imagining you need to create a loop and loop through each object individually, the method does not look like it accepts a list of objects. Since it outputs a massive amount of data, you’re then going to need to collect the data in separate lists and then add/average them as needed to get the result…

Alternatively, you could simply script the Rhino command rs.Command("-VolumeMoments File filename) (with dash) and then open the text file and parse that, or maybe there’s a way to parse clipboard text?

–Mitch

Hey Mitch,

thanks a lot for your message!
I thought about a loop too … but it would be a lot of work to add/average all the results.
Especially when you’re used to the easy & elegant “volumeMoments”-command ^^
… but probably it’s the only way …

I’ll try your second suggestion … perhaps this works too … I’ll let you know :smiley:

Thanks again,
Phil

Hey Mitch,

I tried both methods and after all, I decided to used the rs.Command-command – the determination of the moments of inertia is the last step in my script, so it’s no problem to use this command and to make the user select the volumes he (or she) needs.

Thanks again!
Phil