Adding my own Object Properties. Can I?

I’m working on an assembly and wish to export the Volume Centroids as a csv file. No problem, I can do that. But can I add my own properties, particularly a weight/mass for each item, so I can do some centre of gravity calculations with the exported data in a spreadsheet? Or am I going to have to add them manually in the spreadsheet?

Thanks in advance.

Tim

PS working in Both Rhino 4 and 5, although for this job I would prefer V4. Don’t ask…

This should be easily scriptable… Someone might even already have one of these floating around. If you need real weight, you might have to supply a material density which can be multiplied by the volume calculation… Do you need any other object data exported?

–Mitch

Hi Tim,

Try this one:
volumeMassWeightCentroids.py (7.3 KB)
It check for your unit system and in accordance to that, exports the data in the following way:

  • units: millimeters: length(mm), volume(mm3), mass(g)
  • units: centimeters: length(cm), volume(cm3), mass(g)
  • units: meters: length(m), volume(m3), mass(kg)
  • units: inches: length(in), volume(in3), mass(oz - ounce)
  • units: feets: length(ft), volume(ft3), mass(lb)

The weight is always given in Newtons, no matter what unit system you have. This could easily be changed into KiloNewtons (just additionally multiply the line 84 with “0.001”. Like so: weight = mass * massFactor * 9.81 * 0.001

I took the metal alloy material densities data from here. If you want to add more materials, you could do that by yourself. Just add the material’s name at the end or beginning of list (line 11 in the attached .py file) and its respective density to the list in the line 12.

Apart from exporting a data into .csv file, it also adds labels of object’s number’s and volume centroid points to the Rhino file:

djordje, that is excellent! Thanks indeed, that will do exactly what I need! I very much apreciate you help with this.

Tim

No problem.

Tried to make a button out of it but an issue emerged. Seems like once, the function gets to the line: unitsystemIndex = rs.UnitSystem() instead of further continuing to execute the code, it quits the function and opens “Document Properties” window. Is that some sort of a bug?
@stevebaer any thoughts?

Here is the toolbar with mentioned button:
exportDataToCSV.rui (9.1 KB)

Hi djordje, I have had a go with your script, and edited it a little to my own purposes, but having never worked in Python before, I am a bit out of my depth here!! Is there any way I can change things so instead of each item being labeled obj01 etc, it extracted the appropriate part name from the part properties? It would be wonderful to label each line as, for example, bolt01, hull left, wheel, etc, directly, rather than having to edit the imported data in Excel.

Thanks in advance,

Tim

ps I’ve started reading the Python for Rhino 5 document already!

Hi Tim,

By “part name from part properties” you mean “Object name” (set by using “SetObjectName” command)?
If that is so, then try the edited version: volumeMassWeightCentroids2.py (7.5 KB)
For those objects which do not have their names set, the old labeling of “obj i” will remain. Hope this helps:

Since you might not be using Rhino 5, and thus would not have access to RhinoPython, here is a similar example in RhinoScript:

https://github.com/mcneel/rhinoscript/blob/master/SolidWeight.rvb

You will need to modify the sample if you want to export the results to a .CSV file.