Hi I have some strange problem. When I Add a parameter with add by value as this:
oUserParams.AddByValue("FlatPatternWidth", SheetMetal.FlatExtentsWidth, Inventor.UnitsTypeEnum.kMillimeterLengthUnits)
it put the value 10 times the actual value. when I msgbox(SheetMetal.FlatExtentsWidth) it gives the correct value so the problem is Inventor.UnitsTypeEnum.kMillimeterLengthUnits. if I Change it to
Inventor.UnitsTypeEnum.kCentimeterLengthUnits I got correct measure but wrong unit in parameters.
Why do I need to make the SheetMetal.FlatExtentsWidth/10 for it to work?
Solved! Go to Solution.
Solved by andreas.jonssonF98YC. Go to Solution.
I think it is a strange way of doing this. The unit does not seem to take any notice what the input is, in this case sheetmetal.width that are in mm. here is sheetmetal.width 10 mm but to get it to work with the mm unit i need to divided it by 10 like this msgbox
to get correct value in parameters.
why am I needed to change a value that are correct from start and make it smaller to be correct?
this code shows correct value but I find it strange.
When inputting a parameter the value itself is not controlled by the units of the parameter. This will alter the display value after the parameter has been applied. So you need to figure out first what units the value have on input.
From this post the illogic sheetmetal function uses the document units.
Here is the helpfile for userparameters.addbyvalue.
Where it mentions what units are being used database units (cm). It is up to the user to know what values are being supplied as data based units or documents units etc.
You could also use the expression method and type in the string value of your measurement.
Syntax
UserParameters.AddByExpression( Name As String, Expression As String, UnitsSpecifier As Variant ) As UserParameter
As long as you know what type of units you want to input there is built in conversion:
'DefineConversion for databaseunits
Dim LengthDatabaseUnit As UnitsTypeEnum = UnitsTypeEnum.kDatabaseLengthUnits
Dim LengthUserUnit As UnitsTypeEnum = UnitsTypeEnum.kMillimeterLengthUnits
'Convert Value
Dim convertedValue As Double = ThisApplication.UnitsOfMeasure.ConvertUnits(SheetMetal.FlatExtentsWidth, LengthUserUnit, LengthDatabaseUnit)
'Give value to specified parameter
oUserParams.AddByValue("FlatPatternWidth", convertedValue, LengthUserUnit)
found the root to the problem, I had converted the values before from cm to millimeter and then the addbyvalue is in cm so thereby the problem. however I think it is strange that it does not feel what units it puts in. i put in mm and need to divide by 10 to get mm.
Can't find what you're looking for? Ask the community or share your knowledge.