Hey, thank you for last post. It really helped me to get behind this python-script. Since i have no experience in programming at all, the comments in this code made my day.
I took your code and expanded it a little, so that the script will now (in Rhino 6) give out Volume and Weight, and write this in each UserText of the object. This might help with bigger objects (of the same density).
My Problem now is, that Blocks in the file just crash the script for me. Is there some way i can tell the “rs.GetObjects(…)” to pick each single part of the Block? And by any chance then to force the “rs.SetUserText()” to write the Values into the Block itself? I looked a little in this syntax-description, but in my code this does not help to pick the parts of the block.
Nontheless, thank you for your documentation. I will set my code attached, too.
import rhinoscriptsyntax as rs
dens = rs.RealBox(message=“Density of Material in kg/m^3”, default_number=8000, title=“Density of Material”, minimum=None, maximum=None) #Textbox to Pick Density of Material Used.
object_id = rs.GetObjects(message=“Bla”, preselect=True)#Select an Object. Is there some way to pick parts of a block?
sum = 0 #Sum of the weight of all Objects.Has to be Zero Before the For command.
float(sum)#Has to be a float (i guess)
for object_i in object_id: #Loop between the objects
rs.Command(”-_selnone") #deselect any objects
object_i = str(object_i)
block = rs.Command("-_SelID " + object_i) #get block id
i = rs.coercebrep(object_i)
blockVolume = i.GetVolume()#getvolume
Vol1 = ("%.2f" % blockVolume)#Set Value behind comma
Vol = str(Vol1)#change into str
rs.SetUserText(object_i, “Volumen in mm^3”, value=Vol)#Write Volume into Usertext. Some way to write this into the Block?
dens1 = (dens*0.000000001) # Density from kg/m^3 in kg/mm
weight1 = (dens1 * blockVolume) #Weight of the Part
weight2 = ("%.2f" % weight1)#Set Value behind comma
weight = str(weight2)#weight into str
rs.SetUserText(object_i, “Gewicht in kg”, value=weight)#write value into User Text.Some way to write this into the Block?
weight3 = float(weight)#make weight a float
sum += weight3 #add weight of the part to the total weight
print sum # print the total weight after every part.find out how to change that