Get UnitTypeEnum from UnitsOfMeasure for "Text" and "Boolean"

Get UnitTypeEnum from UnitsOfMeasure for "Text" and "Boolean"

Anonymous
Not applicable
2,157 Views
5 Replies
Message 1 of 6

Get UnitTypeEnum from UnitsOfMeasure for "Text" and "Boolean"

Anonymous
Not applicable

I'm using the UnitsOfMeasure.GetTypeFromString() method to identify and handle different units, but it seems that the method doesn't handle "Text" or "Boolean" even though kTextUnits and kBooleanUnits are valid values of the enum. Is this expected behavior or is there something I'm doing wrong? I have resorted to handling those strings before calling the helper function but I would like to be able to simplify and use only it.

 

Related to this, why is UserParameter.Unit not directly accessible in C#? Calling the getter (UserParameter.get_Unit) works, but seems messy and gets flagged by my linter...

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

flora_fang
Autodesk
Autodesk

Hi, for the first question, UnitsOfMeasure.GetTypeFromString() couldn't work for Text or Boolean, it sounds like as design from my understanding. Here is the list of unit that support by GetTypeFromString method, hope that helps. 

kDefaultDisplayLengthUnit

kCentimeterLengthUnit

kMillimeterLengthUnit

kMeterLengthUnit

kMicronLengthUnit

kInchLengthUnit

kFootLengthUnit

kYardLengthUnit

kMileLengthUnit

kNauticalMileLengthUnit

kMilLengthUnit

 

kDefaultDisplayMassUnit

kKilogramMassUnit

kGramMassUnit

kSlugMassUnit

kLbMassMassUnit

kOunceMassMassUnit

 

kDefaultDisplayTimeUnit

kSecondTimeUnit

kMinuteTimeUnit

kHourTimeUnit

 

kDefaultDisplayTemperatureUnit

kKelvinTemperatureUnit

kCelsiusTemperatureUnit

kFarenheitTemperatureUnit

 

kDefaultDisplayAngleUnit

kRadianAngleUnit

kDegreeAngleUnit

kGradAngleUnit

kSteradianAngleUnit

 

kUnitlessUnit

 

kMetersPerSecondSpeedUnit

kFeetPerSecondSpeedUnit

kMilesPerHourSpeedUnit

 

kAcreAreaUnit

kCircularMilAreaUnit

 

kLiterVolumeUnit

kGallonVolumeUnit

kQuartVolumeUnit

kPintVolumeUnit

kCupVolumeUnit

kOunceVolumeUnit

 

kPascalPressureUnit

kPSIPressureUnit

kKSIPressureUnit

 

kNewtonForceUnit

kDyneForceUnit

kLbForceUnit

kOunceForceUnit

 

kWattPowerUnit

kHorsePowerPowerUnit

 

kJouleWorkUnit

kErgWorkUnit

kCalorieWorkUnit

kBtuWorkUnit

 

kRpmAngularVelocityUnit

 

kAmpElectricalUnit

kVoltElectricalUnit

kOhmElectricalUnit

kCoulombElectricalUnit

kFaradElectricalUnit

kSiemensElectricalUnit

kmhoElectricalUnit

kWeberElectricalUnit

kMaxwellElectricalUnit

kTeslaElectricalUnit

kGammaElectricalUnit

kGaussElectricalUnit

kHenryElectricalUnit

kOerstedElectricalUnit

kHertzElectricalUnit

 

kCandelaLuminosityUnit

kLumenLuminosityUnit

kLuxLuminosityUnit

 

kMoleSubstanceUnit



Flora Fang
Flora.Fang@autodesk.com
Software Quality Assurance
Design & Manufacturing
Autodesk, Inc.

0 Likes
Message 3 of 6

Anonymous
Not applicable

This shouldn't be by design...

UnitsOfMeasure.GetTypeFromString documentation says: "UnitsOfMeasure.GetTypeFromString Method : Given a string defining a unit this method returns the corresponding unit from the UnitsTypeEnum constant list". 

kBooleanUnits and kTextUnits are both existing values in the UnitsTypeEnum. Parameter.get_Unit (which returns a string representing the unit) can return "Text" and "Boolean" because kBooleanUnits/kTextUnits are valid UnitsSpecifier and can be passed when creating the Parameter.

So calling :

 

 

UnitsOfMeasure.GetTypeFromString( Parameter.get_Unit() )

 

 

will occasionally fail because the acceptable inputs to the helper method are a narrower subset of the UnitsTypeEnum than the possible values of the Parameter.Unit property...if that's the expected behavior it would be nice to at least have it documented somewhere.

 

0 Likes
Message 4 of 6

ekinsb
Alumni
Alumni
Accepted solution

I would tend to agree with you.  The current behavior isn't really by design but is more just by default.  Originally, Inventor only supported value parameters and String and Boolean parameters were added later.  We had to figure out a way to add support for these new types into the API without breaking the existing behavior.  It looks like the Units property was overlooked and wasn't updated to add support for these new types.  The good news is that it's relatively easy to workaround this, which you're already doing.

 

Regarding your other question about the Units property, I just looked at it and confirmed what you said.  I don't beleive this is anything that we're doing in the API definition but is something that C# is doing instead.  Visual Basic uses the same interop library and the Units property is available there.  I don't know why C# chooses to expose it as the get_Units and set_Units functions instead.  I'm guessing there's an issue with using "Units" but it doesn't seem to be a reserved keyword so I don't know why it's doing what it is.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 5 of 6

Anonymous
Not applicable

Brian, thanks for clearing that up. I spent a couple hours stepping through code trying to figure out why it was (inconsistently) crashing, before I figured out that those values were the problem. Are the internals of the GetTypeFromString helper method anything more than a big switch statement handling each unit case? I don't think it would be difficult or a breaking change to add handling code for "Text" and "Boolean". A small change in the backend but an improvement for API consistency.

As for point 2 - it's baffled me as well. I guess it's just something funny happening with C# Properties.

0 Likes
Message 6 of 6

Maxim-CADman77
Advisor
Advisor

@flora_fang 
What is the source of this list and whether it got any changes for the past 7 years?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes