unitsManager.formatValue unexpected keyword argument 'showUnits'

unitsManager.formatValue unexpected keyword argument 'showUnits'

YouElz
Contributor Contributor
363 Views
1 Reply
Message 1 of 2

unitsManager.formatValue unexpected keyword argument 'showUnits'

YouElz
Contributor
Contributor

Hi everyone 

can anyone point out why I am getting his error? I am still learning but I have spent few hours already searching but no avail. Thank you. 

 

 

Failed:
Traceback (most recent call last):
  File "C:/Users/YouElz/Desktop/Python/Fusion 360/TestScript/TestScript.py", line 29, in run
    length = unitsMgr.formatValue(3.20, showUnits=False)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: FusionUnitsManager.formatValue() got an unexpected keyword argument 'showUnits'

 

def run(context):
    try:
        global _app, _ui, _design
        _app = adsk.core.Application.get()
        _ui = _app.userInterface
        _design = adsk.fusion.Design.cast(_app.activeProduct)

        unitsMgr = _design.unitsManager
        length = unitsMgr.formatValue(3.20, showUnits=False)
        print(length)
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

0 Likes
Accepted solutions (1)
364 Views
1 Reply
Reply (1)
Message 2 of 2

j4n.vokurka
Advocate
Advocate
Accepted solution

Hello,

functions have default and optional parameters. Optional parameters always follow after default parameters. If a function has optional parameters, you can call the function without providing values for them. However, if you skip an optional parameter and provide a value for a latter optional parameter, you will get an error, because it may not be obvious that you have or which parameter you have skipped.

To put it simply, if you want to call this method you always have to provide all the parameters that are defined before the parameter you actually want to use. In your case, that means all of them since showUnits is the last one defined. 

I hope I'm not mystifying here but this is how I understand it in other languages and in Python it should be the same. 

0 Likes