Making input red in our panels so the user knows the values they put are bad

Making input red in our panels so the user knows the values they put are bad

OceanHydroAU
Collaborator Collaborator
720 Views
5 Replies
Message 1 of 6

Making input red in our panels so the user knows the values they put are bad

OceanHydroAU
Collaborator
Collaborator

My Add-in collects user-data - I want to make the numbers they type in go red when they make no sense (e.g. out of range, like negative Reynolds numbers), like how the existing UI does it when we are dimensioning sketches etc.

 

Ideally - I need my code to decide which numbers make no sense, based on the numbers themselves, as well as the other numbers they entered (e.g. a wing chord is OK only for certain reynolds numbers)

 

Is this possible?

 

Assuming not - how would you recommend that I collect a complex set of interdependent values from my users, in a way that holds their hand in real-time?  

 

Specifically - they're inserting an airfoil, and they need to supply some of the following, so I can compute the rest and return the best appropriate one for them:

 

The medium:

  Air (and altitude and temperature)

  Water (and fresh/sea, and depth, and temperature)

  Other (so they need to supply fluid density + dynamic viscosity, or kinematic viscosity)

Their needs:

  Chord

  Velocity

  Target optimization (best l/d or least drag etc)

So I can compute (or they can skip the above and enter directly):-

  Re (Reynolds Number)

 

I want them to be able to use or select whatever units they want (Fahrenheit, knots, mph, m/s etc)

 

Ideally - I want to compute "in real time" (as they type) whatever they left out - e.g. if they supplied the Re, Chord. and Velocity, I want to insert the medium data for them.

0 Likes
Accepted solutions (1)
721 Views
5 Replies
Replies (5)
Message 2 of 6

BrianEkins
Mentor
Mentor

Unfortunately, that's not currently supported but it would be a good feature to add.  Fusion will change the color of ValueCommandInput objects to red if the value entered is invalid, but it does the evaluation on its own and you can't do any custom evaluation.  For example, if I create a ValueCommandInput that has a length unit type and enter "30 deg" it will change to red because it can't be evaluated as a length.  Or if I typed in "A Junk String" it would also change to red because it can't be evaluated as a length.  However, if I type in "100" and I want to limit the length to 50, I can't do that and it will display in black because "100" can be evaluated as a length.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 6

OceanHydroAU
Collaborator
Collaborator

I think I stumbled on a possible answer myself, at least for string values anyhow:

 

This makes it red:

stringValueCommandInput_var.isValueError = True

 

maybe that property can be set on other things even though it's not mentioned in the doc for them?  Even if not, I could always use text for the input of my numbers, and do the checks myself (messy, and would require me to understand expressions too... but might work).

 

Update: rats: lets me set that property for addValueInput - but it does not go red in the UI 😞

0 Likes
Message 4 of 6

BrianEkins
Mentor
Mentor
Accepted solution

Yes, I had forgotten about that property for string value inputs and it actually should be fairly easy to use those for what you need.  All of the complicated work that would get very messy can be handled by the UnitManager object.  When the value changes in the text box you can take the current string and use the UnitManager.isValidExpression to determine if the input is a valid value for the unit type you're using.  If it is then, you can use the UnitManager.evaluateExpression to convert the string to a floating point number in internal units (centimeters if you're working with lengths).  You can then use this value to do any additional custom numerical checks you need to do to validate the number.  If it's OK, you don't do anything.  If it's not, you can set the isValueError to True.

 

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 5 of 6

OceanHydroAU
Collaborator
Collaborator

Brilliant tip!  I'm still learning the UI, and had no idea you'd exposed all the "expression hard work" for us to so easily use 🙂

0 Likes
Message 6 of 6

markSJVQS
Participant
Participant

It would be nice if ALL user Inputs would support a .isValueError property and something like a .valueErrorMessage property.

 

I am having the same challenge of being able to indicate which input(s) have an error and what the error is.

 

The ValidateInputsEvent allows the OK button to be disabled to prevent in valid input(s) to be accepted. But, there is no good way to provide the user any feedback as to which inputs(s) are invalid and why.

 

0 Likes