I'm running into an issue obtaining inertia values from my assembly using NXOpen in Python. I am currently using the NewMassProperties method to obtain mass properties for my assembly. This does not allow me to access inertia tensors, but does allow me to calculate mass, area, volume, spherical radius of gyration, centroid, and weight. This is strange to me since pinging the info window method (i.e. measureBodies.Information()), displays all of the needed inertia values, but I can't seem to access this information via NewMassProperties.
Does anyone know how to grab the inertia moments and tensors using this method? It would be preferable to continue using this method, but it seems that most discussions point me to the AskMassProps3d method. Does anyone have any experience using this to get inertia values in python? Any help would be greatly appreciated.
Also, I'm using NX 10.
Thanks for your help!
Sam
re: python AskMassProps3d
The journal below shows how to call the .AskMassProps3d method. The output could use some polish, but it illustrates how to pull the values out of the returned tuple. The code analyzes the solid bodies of the current work part and reports the results.
import NXOpen
import NXOpen.UF
theSession = NXOpen.Session.GetSession()
theLw = theSession.ListingWindow
theUfSession = NXOpen.UF.UFSession.GetUFSession()
def main():
workPart = theSession.Parts.Work
displayPart = theSession.Parts.Display
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "mass props 3D")
theLw.Open()
# initialize list to hold bodies
theBodyTags = []
for x in theSession.Parts.Work.Bodies:
if x.IsSolidBody:
theBodyTags.append(x.Tag)
# debug
theLw.WriteLine("number of solid bodies: " + str(len(theBodyTags)))
#units: pound inch
(massProps, Stats) = theUfSession.Modeling.AskMassProps3d(theBodyTags, len(theBodyTags), 1, 1, .03, 1, [0.99,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0])
theLw.WriteLine("units: pound, inch")
theLw.WriteLine("surface area: " + str(massProps[0]))
theLw.WriteLine("volume: " + str(massProps[1]))
theLw.WriteLine("mass: " + str(massProps[2]))
theLw.WriteLine("center of mass (WCS): " + str(massProps[3]) + ", " + str(massProps[4]) + ", " + str(massProps[5]))
theLw.WriteLine("first moments (centroidal): " + str(massProps[6]) + ", " + str(massProps[7]) + ", " + str(massProps[8]))
theLw.WriteLine("moments of inertia (WCS): " + str(massProps[9]) + ", " + str(massProps[10]) + ", " + str(massProps[11]))
theLw.WriteLine("moments of inertia (centroidal): " + str(massProps[12]) + ", " + str(massProps[13]) + ", " + str(massProps[14]))
theLw.WriteLine("spherical moment of inertia: " + str(massProps[15]))
theLw.WriteLine("inertia products (WCS): " + str(massProps[16]) + ", " + str(massProps[17]) + ", " + str(massProps[18]))
theLw.WriteLine("inertia products (centroidal): " + str(massProps[19]) + ", " + str(massProps[20]) + ", " + str(massProps[21]))
theLw.WriteLine("prinicpal axes (WCS): [" + str(massProps[22]) + ", " + str(massProps[23]) + ", " + str(massProps[24]) + "] [" + str(massProps[25]) + ", " + str(massProps[26]) + ", " + str(massProps[27]) + "] [" + str(massProps[28]) + ", " + str(massProps[29]) + ", " + str(massProps[30]) + "]")
theLw.WriteLine("principal moments (centroidal): " + str(massProps[31]) + ", " + str(massProps[32]) + ", " + str(massProps[33]))
theLw.WriteLine("radii of gyration (WCS): " + str(massProps[34]) + ", " + str(massProps[35]) + ", " + str(massProps[36]))
theLw.WriteLine("radii of gyration (centroidal): " + str(massProps[37]) + ", " + str(massProps[38]) + ", " + str(massProps[39]))
theLw.WriteLine("spherical radius of gyration: " + str(massProps[40]))
theLw.WriteLine("density: " + str(massProps[46]))
theLw.Close()
if __name__ == '__main__':
main()
Thanks!
Thanks for your help! I was able to implement this code with no problems!
Sam