<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Body physical property with VeryHighCalculationAccuracy in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/body-physical-property-with-veryhighcalculationaccuracy/m-p/9578802#M11433</link>
    <description>&lt;P&gt;I'm trying to get moment of inertia of bodies as precisely as possible.&lt;/P&gt;&lt;P&gt;But the following getPhysicalProperties makes AttributeError:&lt;/P&gt;&lt;P&gt;Is there any other way to get precise physical&amp;nbsp;properties of body&amp;nbsp;?&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using the following code which gives me properties with low precision.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;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 &amp;gt; 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()))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 14 Jun 2020 13:24:03 GMT</pubDate>
    <dc:creator>yamamoto.mas</dc:creator>
    <dc:date>2020-06-14T13:24:03Z</dc:date>
    <item>
      <title>Body physical property with VeryHighCalculationAccuracy</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/body-physical-property-with-veryhighcalculationaccuracy/m-p/9578802#M11433</link>
      <description>&lt;P&gt;I'm trying to get moment of inertia of bodies as precisely as possible.&lt;/P&gt;&lt;P&gt;But the following getPhysicalProperties makes AttributeError:&lt;/P&gt;&lt;P&gt;Is there any other way to get precise physical&amp;nbsp;properties of body&amp;nbsp;?&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using the following code which gives me properties with low precision.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;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 &amp;gt; 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()))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jun 2020 13:24:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/body-physical-property-with-veryhighcalculationaccuracy/m-p/9578802#M11433</guid>
      <dc:creator>yamamoto.mas</dc:creator>
      <dc:date>2020-06-14T13:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: Body physical property with VeryHighCalculationAccuracy</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/body-physical-property-with-veryhighcalculationaccuracy/m-p/9615881#M11434</link>
      <description>&lt;P&gt;Perhaps do not use round()?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AttribueError sounds like a bug you can fix though?&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 05:34:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/body-physical-property-with-veryhighcalculationaccuracy/m-p/9615881#M11434</guid>
      <dc:creator>OceanHydroAU</dc:creator>
      <dc:date>2020-07-03T05:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: Body physical property with VeryHighCalculationAccuracy</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/body-physical-property-with-veryhighcalculationaccuracy/m-p/9616140#M11435</link>
      <description>&lt;P&gt;&amp;gt; &lt;SPAN style="color: #666666;"&gt;&lt;FONT face="ＭＳ Ｐゴシック"&gt;Perhaps do not use round()?&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for a comment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This program is just for displaying data on the UI dialog.&lt;/P&gt;&lt;P&gt;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...&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 08:52:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/body-physical-property-with-veryhighcalculationaccuracy/m-p/9616140#M11435</guid>
      <dc:creator>yamamoto.mas</dc:creator>
      <dc:date>2020-07-03T08:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: Body physical property with VeryHighCalculationAccuracy</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/body-physical-property-with-veryhighcalculationaccuracy/m-p/9617310#M11436</link>
      <description>&lt;P&gt;Unfortunately, there appears to be an oversight in the design of the API.&amp;nbsp; The BRepBody object only supports the physicalProperties property and this doesn't let you define the accuracy.&amp;nbsp; It should also support the getPhysicalProperties method like some other objects do.&amp;nbsp; I've reported this to Autodesk and hopefully it's addressed soon.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jul 2020 00:41:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/body-physical-property-with-veryhighcalculationaccuracy/m-p/9617310#M11436</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2020-07-04T00:41:17Z</dc:date>
    </item>
  </channel>
</rss>

