Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

getting center of mass in mm

fusion360_Admin4QV4K
Explorer

getting center of mass in mm

fusion360_Admin4QV4K
Explorer
Explorer
Hello.
I am trying to write a script to parse through all components and write their XYZ coordinates to a file. So far everything works except the XYZ coordinates. What I get are insanely large values. How can I convert these values to say.. MM?
Example:
if I use "x = child.physicalProperties.centerOfMass.x"
I will get a HUGE number like -0.2487257213245866
(the actual value in mm is 26.5002)
I am trying to get the center of mass.
0 Likes
Reply
256 Views
2 Replies
Replies (2)

BrianEkins
Mentor
Mentor

You might want to look at the User Manual topic on units. When using the API, all distance values are in centimeters. The value you're seeing is in centimeters. The value (-0.2487257213245866) is not big. There's a decimal point at the beginning so it's less than 1/4 of the centimeter or -2.487 mm. There are a lot of digits because Fusion is doing the calculations using double-precision floating point numbers. Using formatting options, you can always choose to round to a specific precision. You can also use the UnitsManager object to convert the value into a string that uses the user's current units and the precision they've specified in their preferences.

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

kandennti
Mentor
Mentor

Hi @fusion360_Admin4QV4K .

 

Fusion360's internal unit of length is "Cm".
It is recommended to use the UnitsManager.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-GUID-9c2d17c1-70c6-4c2d-ae9e-c6f6f283b1a9 

 

If you have set the unit of length to "mm", it will look like this.

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion

def run(context):
    ui = core.UserInterface.cast(None)
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface
        des: fusion.Design = app.activeProduct
        root: fusion.Component = des.rootComponent

        unitsMgr: core.UnitsManager = des.unitsManager

        occ: fusion.Occurrence = None
        for occ in root.allOccurrences:
            props: fusion.PhysicalProperties = occ.physicalProperties
            cog: core.Point3D = props.centerOfMass

            infos = [
                f'** {occ.name} - Center Of Mass**',
                f'X:{unitsMgr.formatInternalValue(cog.x)}',
                f'Y:{unitsMgr.formatInternalValue(cog.y)}',
                f'Z:{unitsMgr.formatInternalValue(cog.z)}',
            ]
            app.log('\n'.join(infos))

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

If you want to specify the unit, you can change it to this.

                f'X:{unitsMgr.formatInternalValue(cog.x, "mm")}',
                f'Y:{unitsMgr.formatInternalValue(cog.y, "mm")}',
                f'Z:{unitsMgr.formatInternalValue(cog.z, "mm")}',
0 Likes