How to get the combined space claim mass properties?
M
Member, Employee Posts: 244
✭✭✭✭
V2021R2
A customer recently requested the mass properties of selected bodies in SpaceClaim. Does anyone know a direct way to get this data?
Tagged:
0
Best Answers
-
And because this is StackOverflow, I can add my own (partial) answer. What I did was to grab all the bodies, copy them, combine them and get the properties of that new body, and then delete it.
bodyList = [] bodyProps = {} def GETPROPS(body): """ function to get the required properties from a bodz""" x,y,z = body.Shape.GetExtremePoint(Direction.DirX,Direction.DirY,Direction.DirZ) vol = body.Shape.Volume bmp = body.MassProperties mass = bmp.Mass pax = body.MassProperties.PrincipleAxes.AxisX principalMomentXAxis = body.MassProperties.GetMoment(pax) paxD = pax.Direction pay = body.MassProperties.PrincipleAxes.AxisY principalMomentYAxis = body.MassProperties.GetMoment(pay) payD = pay.Direction paz = body.MassProperties.PrincipleAxes.AxisZ principalMomentZAxis = body.MassProperties.GetMoment(paz) pazD = paz.Direction props = [vol,mass,principalMomentXAxis,paxD,principalMomentYAxis,payD,principalMomentZAxis,pazD] return props def GETNEW(bodyList): """function to sort the lists when a new body is added to SC""" newlyCreated = [] for body in GetRootPart().GetAllBodies(): if body not in bodyList: newlyCreated.append(body) return newlyCreated for body in GetRootPart().GetAllBodies(): bodyName = body.GetName() bodyProps[bodyName] = GETPROPS(body) bodyList.append(body) # copy all the bodyList bodies bodySelection = Selection.Create(bodyList) result = Copy.Execute(Selection.Create(bodyList)) # Get the new bodies to a list newlyCreated = GETNEW(bodyList) # combine only these new bodies targets = BodySelection.Create(newlyCreated) result = Combine.Merge(targets) # get the list of newly created bodies (should be 1) newlyCreated = GETNEW(bodyList) # Get properties of the body bodyProps['Combined'] = GETPROPS(newlyCreated[0]) # remove body from SC newlyCreated[0].Delete()
I am hoping there is a direct way. Perhaps if the parts are selected?
10 -
meister Mladenov to the rescue:
selection = BodySelection.Create(GetRootPart().Bodies) massProps = MeasureHelper.GetMassProperties(selection) mass = massProps.Mass pax = massProps.PrincipleAxes.AxisX pay = massProps.PrincipleAxes.AxisY paz = massProps.PrincipleAxes.AxisZ principalMomentXAxis = massProps.GetMoment(pax) principalMomentYAxis = massProps.GetMoment(pay) principalMomentZAxis = massProps.GetMoment(paz) paxD = pax.Direction payD = pay.Direction pazD = paz.Direction
0
Answers
-
to add, in order to get the centre of volume:
mp=body.MassProperties.RawSubject cen=mp.Center
0