Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with units addbyvalue. Inventor 2023

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
andreas.jonssonF98YC
330 Views, 7 Replies

Problem with units addbyvalue. Inventor 2023

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? 

andreasjonssonF98YC_0-1685357319161.png

andreasjonssonF98YC_1-1685357467232.png

 

 

7 REPLIES 7
Message 2 of 8

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

 


andreasjonssonF98YC_0-1685358249965.png

to get correct value in parameters. 

andreasjonssonF98YC_1-1685358506831.png

 

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.

'look for user parameter SheetMetalWidth and try to set it       
Try
oUserParams.Item("FlatPatternWidth").Value = SheetMetal.FlatExtentsWidth/10
msgbox(oUserParams.Item("FlatPatternWidth").Value)
Catch
' assume error means not found and create it
oUserParams.AddByValue("FlatPatternWidth", SheetMetal.FlatExtentsWidth/10, Inventor.UnitsTypeEnum.kMillimeterLengthUnits)
End Try

 

Message 3 of 8

Hi @andreas.jonssonF98YC 

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.   

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 4 of 8

The input sheetmetal width and height is in mm. however the addbyvalue are hardcoded to cm and then controlled by the Inventor.UnitsTypeEnum.kMillimeterLengthUnits which makes the whole not understandable. since the value is coded to CM I need to divide my correct answer with 10 and then put Inventor.UnitsTypeEnum.kMillimeterLengthUnits for it to multiply with 10 again. thereby is not the calculated value correct even if it is in millimeters from start.

This is really a strange way to code and it could have been expensive for our company with 10 times to big sheet metal parts.
Message 5 of 8

Hi @andreas.jonssonF98YC 

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.AddByExpressionName As String, Expression As String, UnitsSpecifier As Variant ) As UserParameter

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 6 of 8

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)
Message 7 of 8

IV use cm internally.

Message 8 of 8

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.

Post to forums  

Technology Administrators


Autodesk Design & Make Report