Body physical property with VeryHighCalculationAccuracy

Body physical property with VeryHighCalculationAccuracy

yamamoto.mas
Contributor Contributor
1,513 Views
3 Replies
Message 1 of 4

Body physical property with VeryHighCalculationAccuracy

yamamoto.mas
Contributor
Contributor

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

 

 

0 Likes
Accepted solutions (1)
1,514 Views
3 Replies
Replies (3)
Message 2 of 4

OceanHydroAU
Collaborator
Collaborator

Perhaps do not use round()?

 

AttribueError sounds like a bug you can fix though?

0 Likes
Message 3 of 4

yamamoto.mas
Contributor
Contributor

> 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...

0 Likes
Message 4 of 4

BrianEkins
Mentor
Mentor
Accepted solution

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