"51" is not an integer?

"51" is not an integer?

Anonymous
Not applicable
1,582 Views
11 Replies
Message 1 of 12

"51" is not an integer?

Anonymous
Not applicable

I created a short Rule to change the iProperties of a part as I change the length of a piece of pipe (I know iParts would be the best way to create similar parts of different length, but it's a long story how I got to this point.) The length of pipe is either a whole number (#) or halfway between two numbers (#.5) My rule basically checks to see if the input is an integer or not and outputs a title and description that follows the nomenclature of my company. When I got to length of 51, my rule assumes it is not an integer, however any other integer, be it 49, 50 or 52, the rule works fine.

 

Why isn't "51" an integer?

 

Here is my code, where d2 is the length of the pipe:

If d2 = Int(d2) Then
iProperties.Value("Project", "Description") = "TUBING, 1.500 OD X 0.125 W X " & d2 & ".000 LG"
iProperties.Value("Summary", "Title") = "TUBING, 1.500 OD X 0.125 W X " & d2 & ".000 LG"
MsgBox(d2 & " is an integer")
Else
iProperties.Value("Project", "Description") = "TUBING, 1.500 OD X 0.125 W X " & d2 & "00 LG"
iProperties.Value("Summary", "Title") = "TUBING, 1.500 OD X 0.125 W X " & d2 & "00 LG"
MsgBox(d2 & " is not an integer")
End If

 

I added message boxes to confirm that it thinks 51 is not an integer.

51 is not an integer.PNG

0 Likes
Accepted solutions (1)
1,583 Views
11 Replies
Replies (11)
Message 2 of 12

NachoShaw
Advisor
Advisor

Hey

 

Are you declaring d2 as an integer? Most likely the cause is because it hasnt be 'set' as an integer. Its in your code;

 

If d2 = Int(d2) Then
    iProperties.Value("Project", "Description") = "TUBING, 1.500 OD X 0.125 W X " & d2 & ".000 LG"
    iProperties.Value("Summary", "Title") = "TUBING, 1.500 OD X 0.125 W X " & d2 & ".000 LG"
    MsgBox(d2 & " is an integer")
Else
    iProperties.Value("Project", "Description") = "TUBING, 1.500 OD X 0.125 W X " & d2 & "00 LG"
    iProperties.Value("Summary", "Title") = "TUBING, 1.500 OD X 0.125 W X " & d2 & "00 LG"
    MsgBox(d2 & " is not an integer")
End If

This line

 

If d2 = Int(d2) Then

 

 

is asking if d2 is Int(d2) which i guess is ok but you Else return isnt declaring d2 or asking as an Integer, its just looking at d2. Also, its part of a concatenated description so that may also be formatting it. Maybe try change to this when you set a d2 value Cint(d2) to convert d2 into an Integer. This could be used like this

 

iProperties.Value("Project", "Description") = "TUBING, 1.500 OD X 0.125 W X " & Cint(d2) & ".000 LG"

 

 

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 3 of 12

bradeneuropeArthur
Mentor
Mentor

51 inch is calculated within inventor different.

51 inch will be calculated in cm/mm that is why this is not an integer!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 4 of 12

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Hoping that below iLogic code may be helpful to determine integer number.

Dim val As Double 
val = Convert.ToDouble(d2)

If val Mod 1 = 0 Then	
	iProperties.Value("Project", "Description") = "TUBING, 1.500 OD X 0.125 W X " & d2 & ".000 LG"
	iProperties.Value("Summary", "Title") = "TUBING, 1.500 OD X 0.125 W X " & d2 & ".000 LG"
	MsgBox(d2 & " is an integer")
Else
	iProperties.Value("Project", "Description") = "TUBING, 1.500 OD X 0.125 W X " & d2 & "00 LG"
	iProperties.Value("Summary", "Title") = "TUBING, 1.500 OD X 0.125 W X " & d2 & "00 LG"
	MsgBox(d2 & " is not an integer")
End If

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 12

Anonymous
Not applicable

Hello,

 

Thank you for the response. Unfortunately the code is still insisting 51 is not an integer, which is especially strange because when I add the value of val to the message box, it comes out as 51...

Dim val As Double 
val = Convert.ToDouble(d2)


If val Mod 1 = 0 Then
iProperties.Value("Project", "Description") = "TUBING, 1.500 OD X 0.125 W X " & d2 & ".000 LG"
iProperties.Value("Summary", "Title") = "TUBING, 1.500 OD X 0.125 W X " & d2 & ".000 LG"
MsgBox(d2 & " is an integer. val=" & val)
Else
iProperties.Value("Project", "Description") = "TUBING, 1.500 OD X 0.125 W X " & d2 & "00 LG"
iProperties.Value("Summary", "Title") = "TUBING, 1.500 OD X 0.125 W X " & d2 & "00 LG"
MsgBox(d2 & " is not an integer. val=" & val)
End If

51 is not an integer with val.PNG

 

Perhaps it does have to do with Inventor converting to mm as suggested by @bradeneuropeArthur , but I only get the issue with 51; at least between the values I was inputting which was 38-58.

 

I got the idea through this thread:

https://forums.autodesk.com/t5/inventor-forum/identify-whether-a-parameter-is-a-whole-number-or-deci...

 

Perhaps there is a better way...

 

 

 

0 Likes
Message 6 of 12

clutsa
Collaborator
Collaborator
Accepted solution

I agree with @chandra.shekar.g. The technique he's using is Mod. That asks for what's left over after dividing a number by another number... in this case your tube length Mod (divided) by 1. If the tube is anything but a whole number you'll have something left over (for your case only .5) 

 

Otherwise the below will take care of padding zeros until you get to at least a three place decimal (in case someone decides to add other fractions to your project (you know that's how it always goes)) It doesn't truncate the number if it's more then 3 places to start (that could be added.)

Dim LengthString As String = CStr(Parameter("d2")) 'make a string
DecimalPlace = InStr(1, LengthString, ".") 'look for decimal
If DecimalPlace <> 0 Then 'if a decimal was found
	Do Until Len(Mid(LengthString, DecimalPlace)) > 3 
		LengthString = LengthString & "0" 'add zeros until three places after are made
	Loop
Else
	LengthString = LengthString & ".000" 
End If
iProperties.Value("Project", "Description") = "TUBING, 1.500 OD X 0.125 W X " & LengthString & " LG"
iProperties.Value("Summary", "Title") = "TUBING, 1.500 OD X 0.125 W X " & LengthString & " LG"
'MessageBox.Show(LengthString, "Title")

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 7 of 12

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Can you please provide sample model data (non confidential) to test the behavior?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 12

Anonymous
Not applicable

@chandra.shekar.g 

 

Please attached for the part. As I try different lengths, at least on my system, both 51 and now 52 do not work as desired. I am using the code you suggested using mod. Thank you for your help.

 

 

0 Likes
Message 9 of 12

clutsa
Collaborator
Collaborator

Try the code I used... when I agreed with using Mod I assumed it would work... I'm manipulating strings and they won't care what your number is... and it future ready Smiley Wink

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 10 of 12

Anonymous
Not applicable

@clutsa 

 

Ah, just tried your code and seems to work well. Thank you. 

 

Now I'm more curious then anything else why some number values don't work in my or @chandra.shekar.g 's code as expected.

 

Regards,

Ben

 

 

0 Likes
Message 11 of 12

JamieVJohnson2
Collaborator
Collaborator

This topic is very interesting to me, so I'll chime in here after its been solved, just for conversation's sake.  Inventor thinks in cm for length, that's been established.  Inventor's parameters/properties have to be able to convert data from cm to any other unit type on the fly.  That means they are structured as Double/Float types of data (depending on your level and platform of coding).  So every time you ask Inventor for a value, your getting a double data-type back.  That said; doubles are funky data types, and getting equivalency (a = b) to be true can be at the least, problematic.  It is very possible for 0 to not equal 0 simply because one variable has stored 0 as 0.0000000000001, and the other has it stored as 0.000000090987 or some junk like that.  This is especially true when using trig functions and comparing results.  It is in how the 0/1 bit system is manipulated to create a number.  So the suggested solutions above have some form of rounding performed in advance (round, mod, change type to int).  All those methods attempt to cut off the decimal junk at the end and reduce the value to something that is Definitely comparable within your scope of care.

 

 https://www.nextplatform.com/2019/07/08/new-approach-could-sink-floating-point-computation/

Other data types have been explored, and to switch to them will be just a involved as switching from 32bit to 64bit.  But they look promising.

 

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 12 of 12

Anonymous
Not applicable

This issue drove me crazy until I found out what is causing it. Now, I just use Round function every time I do any calculation before I compare it.

0 Likes