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

change units with api

Anonymous

change units with api

Anonymous
Not applicable

Hi, How do I change units using the API?

 

I've very simplistically tried this:

global _app, _ui, _design
        _app = adsk.core.Application.get()
        _ui = _app.userInterface
        product = _app.activeProduct
        _design = adsk.fusion.Design.cast(product)
        
        _design.unitsManager.defaultLengthUnits = 'm'

based on your documentation (which I also can't link here, another problem I should probably create a forum post about at some point...) Anyway it was from:

As the document says:

"Returns a specialized UnitsManager that can set the default length units and work with parameters.

Defined in namespace "adsk.fusion" and the header file is "adsk/fusion/Fusion/Design.h"."

 

But then you read underneath:

 

"

Property Value

This is a read only property whose value is a FusionUnitsManager."

 

So read only... How can I set it then?

 

0 Likes
Reply
Accepted solutions (1)
2,471 Views
3 Replies
Replies (3)

Anonymous
Not applicable

I've tried also just to do an affine transformation like this  

            mytransf = adsk.core.Matrix3D.create()
            mytransf.setToIdentity()
            global thisdocsunits
            if thisdocsunits == "mm":
                myscaleratio = 1/1000
            elif thisdocsunits == "cm":
                myscaleratio = 1/100
            mytransf.setCell(1,1,myscaleratio)
            mytransf.setCell(2,2,myscaleratio)
            mytransf.setCell(3,3,myscaleratio)

- you see, I just want to export this STL with the right values in it without having to change the document's properties. I believe your exportmanager for the STL is faulty and is not doing the size conversion it should be doing(? well, this is a matter of taste, but SolidWorks does it). The STEP export is working fine, or so it seems.

Backtrace give me the output:

DEBUG:root:could not save stl. Traceback (most recent call last):
  File "C:/Users/Frederico/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/newbadasscommand!/newbadasscommand!.py", line 286, in genlink
    rootComp.occurrences.item(i).transform = thistransf
  File "C:/Users/Frederico/AppData/Local/Autodesk/webdeploy/production/96bbf24ce680e1f0f939cd63033d4708c60a6e96/Api/Python/packages\adsk\fusion.py", line 18832, in <lambda>
    __setattr__ = lambda self, name, value: _swig_setattr(self, Occurrence, name, value)
  File "C:/Users/Frederico/AppData/Local/Autodesk/webdeploy/production/96bbf24ce680e1f0f939cd63033d4708c60a6e96/Api/Python/packages\adsk\fusion.py", line 51, in _swig_setattr
    return _swig_setattr_nondynamic(self,class_type,name,value,0)
  File "C:/Users/Frederico/AppData/Local/Autodesk/webdeploy/production/96bbf24ce680e1f0f939cd63033d4708c60a6e96/Api/Python/packages\adsk\fusion.py", line 44, in _swig_setattr_nondynamic
    if method: return method(self,value)
  File "C:/Users/Frederico/AppData/Local/Autodesk/webdeploy/production/96bbf24ce680e1f0f939cd63033d4708c60a6e96/Api/Python/packages\adsk\fusion.py", line 18947, in _set_transform
    return _fusion.Occurrence__set_transform(self, *args)
RuntimeError: 2 : InternalValidationError : pMatrix->isValidNonScaledTransformMatrix()

Thank you very much for you help in advance!
Frederico.

0 Likes

goyals
Autodesk
Autodesk
Accepted solution

Hi,

 

You can change the units following below code.

 

design = adsk.fusion.Design.cast(app.activeProduct)

unitsMgr = design.fusionUnitsManager

unitsMgr.distanceDisplayUnits = adsk.fusion.DistanceUnits.MeterDistanceUnits

 

Regards,

Shyam Goyal



Shyam Goyal
Sr. Software Dev. Manager
1 Like

Anonymous
Not applicable

works like a charm.
Thank you!

0 Likes