Trailing Zeros

Trailing Zeros

cgchad
Contributor Contributor
107 Views
8 Replies
Message 1 of 9

Trailing Zeros

cgchad
Contributor
Contributor

I know this has been asked dozens of times but for some reason I can't get it to work out.  I am running Inventor Professional 2024.

I have 2 parameters that i need to display with just 2 decimal places.  Even if those decimal places are zeros.  No matter what I have done it stops when it's a whole number or has something like .70 it will change to .7.

 

My code for this is currently:

'round values
LENGTH = Round(SheetMetal.FlatExtentsLength, 2) 
WIDTH = Round(SheetMetal.FlatExtentsWidth, 2)

'set raw part information iProperties.Value("Project", "Stock Number") = "HRS " & iProperties.Value("Custom", "GAUGE") & " x " & WIDTH & " x " & LENGTH

 The result is 

cgchad_1-1757437736269.png

I need something like this to appear as 23.00 instead of a whole number.

 

0 Likes
Accepted solutions (1)
108 Views
8 Replies
Replies (8)
Message 2 of 9

J_Pfeifer_
Advocate
Advocate

Alright I messed about with this a bit. Here is the code I used for testing. 

 

Dim Height As Double = tank_id
Dim Width As Double = tank_height

Dim HeightString As String = CStr(Height)
Dim WidthString As String = CStr(Width)

Dim HeightParam As Inventor.Parameter = ThisApplication.ActiveDocument.componentDefinition.Parameters.Item("tank_id")
Dim WidthParam As Inventor.Parameter = ThisApplication.ActiveDocument.componentDefinition.Parameters.Item("tank_height")

HeightParam.Precision = 3 'I wish this worked to control the decimals displayed from either the expression or value. 
WidthParam.Precision = 3

Dim HeightSubString As String() = HeightParam.Expression.Split(" "c) 
Dim WidthSubString As String() = WidthParam.Expression.Split(" "c)


Logger.Info("Height blue value: " & tank_id & " Height double: " & Height & " Height String: " & HeightString & " Height param expression: " & HeightParam.Expression & " Height param value direct: " & HeightParam.Value / 2.54 & " Height substring: " & HeightSubString(0))
Logger.Info("Width blue value: "  & tank_height & " Widdth double: " & Width & "  Width String: " & WidthString & " Width param expression: " & WidthParam.Expression & " Width param value direct: " & HeightParam.Value / 2.54 & " Width substring: " & WidthSubString(0))

 

Log result:

INFO| Height blue value: 120.5 Height double: 120.5 Height String: 120 Height param expression: 120.50 in Height param value direct: 120.5 Height substring: 120.50
INFO| Width blue value: 120.5 Width double: 120.5 Width String: 120 Width param expression: 120.50 in Width param value direct: 120.5 Width substring: 120.50

 

It looks like the expression will contain exactly what you're looking for, the downside is it also contains the unit value. This is where I then split the strings to remove the "in" unit.

 

Watch there be line a single line solution one of these wizards has used. 

0 Likes
Message 3 of 9

cgchad
Contributor
Contributor

I'll give a variant of that a try, but I'm curious how it will turn out since I am pulling an API function in instead of a dim.

0 Likes
Message 4 of 9

J-Camper
Advisor
Advisor

@cgchad ,

This should do it:

'round values
LENGTH = Round(SheetMetal.FlatExtentsLength, 2) 
WIDTH = Round(SheetMetal.FlatExtentsWidth, 2)

'set raw part information
iProperties.Value("Project", "Stock Number") = "HRS " & iProperties.Value("Custom", "GAUGE") & " x " & FormatNumber(WIDTH, 2) & " x " & FormatNumber(LENGTH, 2)
0 Likes
Message 5 of 9

cgchad
Contributor
Contributor

That gives some kind of "currency" error

cgchad_0-1757502887337.png

 

0 Likes
Message 6 of 9

J-Camper
Advisor
Advisor

That is odd, but it looks like you have more logic than you posted.  Can you show me your line 28 mentioned in the error message?  Is it the line I changed?  Seeing the whole rule would be more beneficial to understand what might have gone wrong.

iProperties.Value("Project", "Stock Number") = "HRS " & iProperties.Value("Custom", "GAUGE") & " x " & FormatNumber(WIDTH, 2) & " x " & FormatNumber(LENGTH, 2)

 

 

Another way you could do this is mark "WIDTH" & "LENGTH" For export in the parameters list then set the Custom iProperty Format to text string with 2 decimal places then you could set this equation in your Stock Number iProperty: "=HRS <GAUGE> x <WIDTH> x <LENGTH>".  Then your iLogic would only need to write the FlatExtents values to the "WIDTH" & "LENGTH" Parameters.  The iProperty equation would do the work on combining the 3 iProperties into Stock Number.

0 Likes
Message 7 of 9

cgchad
Contributor
Contributor

Line 28 was the code you shared.  Greatly appreciated but it did result in that error.

The other lines of code before that line are setting gauge definitions, and defining the custom iProperty.  Lines after that point are to give users warnings about weight (Shop limits) or other various things to assist in exporting to our MRP program. Nothing related to this condition.

0 Likes
Message 8 of 9

J-Camper
Advisor
Advisor
Accepted solution

Okay, This should do it:

Dim DoubleLength As Double = Round(SheetMetal.FlatExtentsLength, 2)
Dim DoubleWidth As Double = Round(SheetMetal.FlatExtentsWidth, 2)
LENGTH = DoubleLength
WIDTH = DoubleWidth

'set raw part information
iProperties.Value("Project", "Stock Number") = "HRS " & iProperties.Value("Custom", "GAUGE") & " x " & DoubleWidth.ToString("F2") & " x " & DoubleLength.ToString("F2")


I'm writing the extents values to Double Objects so we can convert those instead of the Parameter Objects.

0 Likes
Message 9 of 9

cgchad
Contributor
Contributor

Thank you.. That did it.  I am still learning iLogic and people like you on these forums has been most helpful.

0 Likes