I am running into many issues when using "percent" or "%" as a unit in the Fusion API.
1) The Units and Value Display preference do not behave as I would expect for ValueInputs with percent units.
☐ Display abbreviations for unit
☐ Display symbols for unit
ValueInput shows "50 percent"
☑︎ Display abbreviations for unit
☐ Display symbols for unit
ValueInput shows "50 %"
☐ Display abbreviations for unit
☑︎ Display symbols for unit
ValueInput shows "50 percent"
☑︎ Display abbreviations for unit
☑︎ Display symbols for unit
ValueInput shows "50 %"
2) When a ValueInput can initially show a "%" but as soon as the user starts to edit the field it turns red, and the only thing the user can do is to replace the "%" with "percent" or to remove the "%" to make the ValueInput happy.
Even if the user makes no changes, validation of this field eventually fails.
3) Many APIs behave inconsistently or don't work with percent units.
# Initial value can't always be set.
input = inputs.addValueInput(
'name', 'Description',
'percent', adsk.core.ValueInput.createByString('50 %')) # initial value is "0.00 %"
input = inputs.addValueInput(
'name', 'Description',
'percent', adsk.core.ValueInput.createByString('50 percent')) # initial value is "0.00 %"
input = inputs.addValueInput(
'name', 'Description',
'percent', adsk.core.ValueInput.createByString('50')) # initial value is "0.00 %"
input = inputs.addValueInput(
'name', 'Description',
'percent', adsk.core.ValueInput.createByReal(0.5)) # initial value is "50.00 %"
# ValueInput.maximumValue behaves inconsistently. Neither of these value work in all cases:
input.maximumValue = 1
input.maximumValue = 100
unitsManager = adsk.core.Application.get().activeProduct.unitsManager
unitsManager.evaluateExpression('50 %', '%') # FAILS
unitsManager.evaluateExpression('50 %', 'percent') # FAILS
unitsManager.evaluateExpression('50 percent', 'percent') # works
unitsManager.evaluateExpression('50', 'percent') # works
unitsManager.formatUnits('%') # FAILS
unitsManager.formatUnits('percent') -> '%'
unitsManager.standardizeExpression('50 %') # FAILS
unitsManager.standardizeExpression('50 percent') # FAILS
# All of the below FAIL.
customFeatureInput.addCustomParameter('name', 'Description', adsk.core.ValueInput.createByString('50 %'), '%') # FAILS
customFeatureInput.addCustomParameter('name', 'Description', adsk.core.ValueInput.createByString('50 percent'), 'percent') # FAILS
customFeatureInput.addCustomParameter('name', 'Description', adsk.core.ValueInput.createByString('50'), 'percent') # FAILS
customFeatureInput.addCustomParameter('name', 'Description', adsk.core.ValueInput.createByReal(50), 'percent') # FAILS
As is, percentage units are unusable.
Hey Autodesk, can you fix this please?