Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to get moment of inertia of bodies as precisely as possible.
But the following getPhysicalProperties makes AttributeError:
Is there any other way to get precise physical properties of body ?
I'm using the following code which gives me properties with low precision.
import adsk.core, adsk.fusion, traceback
def spacePadRight(value, length):
pad = ''
if type(value) is str:
paddingLength = length - len(value) + 1
else:
paddingLength = length - value + 1
while paddingLength > 0:
pad += ' '
paddingLength -= 1
return str(value) + pad
def walkThrough(bom):
mStr = ''
for item in bom:
mStr += spacePadRight(item['name'], 15) + spacePadRight(item['i1'], 10) + spacePadRight(item['i2'], 10) + str(item['i3']) + '\n'
mStr += spacePadRight(item['name'], 15) + spacePadRight(item['rx'], 10) + spacePadRight(item['ry'], 10) + str(item['rz']) + '\n'
return mStr
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
title = 'Extract Primitive'
if not design:
ui.messageBox('No active design', title)
return
# Get all occurrences in the root component of the active design
root = design.rootComponent
occs = root.allOccurrences
# Gather information about each unique component
bom = []
occ = occs[0]
comp = occ.component
bodies = comp.bRepBodies
for bodyK in bodies:
if bodyK.isSolid:
physicalProperties = bodyK.physicalProperties
# physicalProperties = bodyK.getPhysicalProperties(adsk.fusion.CalculationAccuracy.VeryHighCalculationAccuracy)
(retVal, i1, i2, i3) = physicalProperties.getPrincipalMomentsOfInertia()
(retVal, rx, ry, rz) = physicalProperties.getRotationToPrincipal()
# Add this component to the BOM
bom.append({
'name': bodyK.name,
'i1': round(i1,3),
'i2': round(i2,3),
'i3': round(i3,3),
'rx': round(rx,3),
'ry': round(ry,3),
'rz': round(rz,3),
})
msg = walkThrough(bom)
ui.messageBox(msg, 'Bill Of Materials')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.