unitless input

grosfaignan
Enthusiast

unitless input

grosfaignan
Enthusiast
Enthusiast

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 ?

0 Likes
Reply
329 Views
4 Replies
Replies (4)

Jorge_Jaramillo
Collaborator
Collaborator

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

 

0 Likes

grosfaignan
Enthusiast
Enthusiast
i would meen input HAVE to be unitless, i don't want to check results, i just want do discard unit from them
0 Likes

Jorge_Jaramillo
Collaborator
Collaborator

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

 

0 Likes

grosfaignan
Enthusiast
Enthusiast

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.

 

0 Likes