Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Body physical property with VeryHighCalculationAccuracy

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
yamamoto.mas
440 Views, 3 Replies

Body physical property with VeryHighCalculationAccuracy

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()))

 

 

Labels (1)
3 REPLIES 3
Message 2 of 4
OceanHydroAU
in reply to: yamamoto.mas

Perhaps do not use round()?

 

AttribueError sounds like a bug you can fix though?

Message 3 of 4
yamamoto.mas
in reply to: OceanHydroAU

> Perhaps do not use round()?

 

Thanks for a comment.

 

This program is just for displaying data on the UI dialog.

In reality, another function calculates the body's shape and orientation with the assumption that the body is a cuboid. If I can get higher precision physical properties, I can get better estimation...

Message 4 of 4
BrianEkins
in reply to: yamamoto.mas

Unfortunately, there appears to be an oversight in the design of the API.  The BRepBody object only supports the physicalProperties property and this doesn't let you define the accuracy.  It should also support the getPhysicalProperties method like some other objects do.  I've reported this to Autodesk and hopefully it's addressed soon.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report