Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

unitless input

4 REPLIES 4
Reply
Message 1 of 5
grosfaignan
121 Views, 4 Replies

unitless input

hi there,

 

how can i catch unitless input from user in fusion360 API ?

 

thanks

 

[EDIT] i tried someting like that :

 

 

var = adsk.core.ValueInput.evaluateExpression(input.expression, "")
 
var2= adsk.core.ValueInput.createByString(defautlStringNumber)
            inputs.addValueInput('FretQuantity', 'Fret Quantity', "", var2)

 

 

but i'm not able to confirm it works, anyone cand confirm it ?

4 REPLIES 4
Message 2 of 5

Hi @grosfaignan ,

 

You can use this following function to validate measurement expression:

def ValidateExpr(expression, unitType):
    des = adsk.fusion.Design.cast(_app.activeProduct)
    unitsMgr = des.unitsManager

    if unitsMgr.isValidExpression(expression, unitType):
        value = unitsMgr.evaluateExpression(expression, unitType)
            return (True, value)
        else:
            return (False, 0)

 

If unitType is empty string ("") the document default units will be used, which I prefer.

You can also use any user or model parameter inside the expression.

 

You might check results by yourself with different combinations.

For further reference see UnitsManager object in API reference.

 

Hope this help.

 

Regards,

Jorge Jaramillo

 

Message 3 of 5

i would meen input HAVE to be unitless, i don't want to check results, i just want do discard unit from them
Message 4 of 5

Hi,

 

Sorry for the confusion.  Since you wrote "catch" I though it was to trap an error in case it was with no units.

 

You can use this:

addValueInput(VALUE_UNITLESS, 'value unitless', '', adsk.core.ValueInput.createByString('defautlStringNumber'))

 

You will see that if you append "mm" or "in" after the number (like "10 mm") the input is highlighted in red, meaning is an invalid input for the field.  You will get the value without units.

Other option is to use addIntegerSpinnerCommandInput instead, if the value is an integer.

 

Regards,

Jorge

 

Message 5 of 5
grosfaignan
in reply to: grosfaignan

from the doc addValueInput take : ID, name, unitType, initialValue,

 

so if i just write somthing like this

 

inputs.addValueInput('ID', 'name', "", initialValue)

and place a unit in the input, it will not be red higlighted.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report