How would I add this string of text to the end of this iLogic code?

How would I add this string of text to the end of this iLogic code?

chris
Advisor Advisor
535 Views
13 Replies
Message 1 of 14

How would I add this string of text to the end of this iLogic code?

chris
Advisor
Advisor

I'm trying to add the string "Yrds" to the end of this iLogic code, but it's giving me an error, I thought concatenating it would be fine, but obviously it is not?

 

WIP = Round(iProperties.Mass, 0)
iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()


VIG = Round(iProperties.Volume, 0)*0.00495113 & " Yrds"
iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()

chris_0-1739249211154.png

 

 

This code is taking a user defined parameter in volume gallons and converting it to volume yards, but I need "Yrds" to show up at the end of it. 

0 Likes
Accepted solutions (3)
536 Views
13 Replies
Replies (13)
Message 2 of 14

Andrii_Humeniuk
Advisor
Advisor

Hi @chris . To place text in a variable, you need to declare this variable as a String. In this case, you need to declare VIG as a String type. This will allow you to place any data in the variable.

Dim VIG As String = Round(iProperties.Volume, 0) * 0.00495113 & " Yrds"

 Variables can be declared as one of the following data typesBooleanByteIntegerLongCurrencySingleDoubleDateString (for variable-length strings), String * length (for fixed-length strings), Object, or Variant. If you don't specify a data type, the Variant data type is assigned by default. You can also create a user-defined type by using the Type statement.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 14

chris
Advisor
Advisor

@Andrii_Humeniuk Thanks, even when I add your code, "Yrds" still doesn't show up in the final result. I even added a new user defined parameter as "text" and tried it, and it also still doesn't show up? weird...?

0 Likes
Message 4 of 14

Zach.Stauffer
Advocate
Advocate

Andrii's code works for me. Are you resetting your parameter somewhere else, or is the document update setting it to something different?

0 Likes
Message 5 of 14

Curtis_Waguespack
Consultant
Consultant

@chris , I didn't see the error from your original message, but your round function might not be working as expected, because it is rounding, but then immediately multiplying by an 8 digit decimal.

 

Here's a quick update.

 

Hope that helps,

Curtis

 

WIP = Round(iProperties.Mass, 0)
iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()


VIG = Round(iProperties.Volume *0.00495113,0) & " Yrds"
iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()
MsgBox(VIG)

 

results:

Curtis_Waguespack_0-1739282956838.png

 

 

 

EESignature

0 Likes
Message 6 of 14

chris
Advisor
Advisor

@Curtis_Waguespack This is what I get when I run that code? I don't know why this part is being difficult...

chris_0-1739285202999.png

 

0 Likes
Message 7 of 14

Curtis_Waguespack
Consultant
Consultant

@chris, I can't think of what it might be (it works as is on my file) , but maybe if you try this "show our work" version it will point us to the issue.  Just post back with info on which line it errors at using this version, and maybe it'll shine some light on the issue.

 

oVol = iProperties.Volume 
oYardsVol = oVol * 0.00495113
oRoundVol = Round(oYardsVol , 0)

VIG = oRoundVol & " Yrds"
MsgBox(VIG)

 

Also, is this a part or assembly?

Is it a model you can attach here (maybe save a copy and strip our the details if needed)?

 

EESignature

0 Likes
Message 8 of 14

chris
Advisor
Advisor

@Curtis_Waguespack  It's just a part (attached 2025 version), what I am trying to get is the yellow text at the end of the results for weight and yards (see image).... note: I changed VIG to be VIY

chris_0-1739288947770.png

 

Message 9 of 14

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Ahh, I see. I think you will need to make the parameter a Text parameter

 

delete it, recreate it as a Text parameter, and then replace it in the form, then it should work.

 

Curtis_Waguespack_0-1739289776707.png

 

Curtis_Waguespack_1-1739289826359.png

 

 

EESignature

0 Likes
Message 10 of 14

chris
Advisor
Advisor

@Curtis_Waguespack The only issue I see with that is in the example you sent back, the total yardage is 17795, but the correct amount should be 131, any idea what is causing the math to be different?

Message 11 of 14

Curtis_Waguespack
Consultant
Consultant
Accepted solution

wait, you want it to calculate correctly too! 😁

 

yeah, so when we changed from a numeric gallons parameter, to a text parameter, we removed the internal conversion or whatever was happening with that parameter, so the code conversion factor needs to change to go from cubic inches ( the document unit) to cubic yards. I think this is correct now.

 

WIP = Round(iProperties.Mass, 0)
iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()


VIY = System.Math.Ceiling(iProperties.Volume / 46660) & " Yrds"
iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()

 

source:

Curtis_Waguespack_0-1739291342550.png

 

EESignature

0 Likes
Message 12 of 14

chris
Advisor
Advisor

@Curtis_Waguespack OH, right, I had it mapped to gallons in parameters, so the 0.00495113 was the wrong number, I forgot that turning it from numeric to text removed the gallons conversion... duh.

 

Thanks for the help!

Message 13 of 14

chris
Advisor
Advisor

@Curtis_Waguespack One last thing, any idea how to get the comma to be at 3 decimal places on the weight?

 

I got this from chat gtp but it doesn't work:

 

 

how would I add the comma at 3 decimal places for this iLogic code: oMass = iProperties.Mass oRoundMass = Round(oMass , 0) WIP2 = oRoundMass & " lbs"
 

ChatGPT said:

To format oRoundMass with a comma as a thousands separator and three decimal places, use the .ToString() method with a custom numeric format:

Updated Code:
vb
CopyEdit
oMass = iProperties.Mass oRoundMass = Round(oMass, 3) ' Round to 3 decimal places WIP2 = oRoundMass.ToString("N3") & " lbs"
Explanation:
  • Round(oMass, 3): Ensures the number is rounded to three decimal places.
  • .ToString("N3"): Formats the number with:
    • Commas as thousands separators.
    • Three decimal places.
Example Outputs:oMass Value WIP2 Output
1234567.891231,234,567.891 lbs
9876.543219,876.543 lbs
1500.11,500.100 lbs

Let me know if you need further refinements! 🚀

 
4o
 
 

You said:

what does ("N3") mean in iLogic
 

ChatGPT said:

In iLogic (which uses VB.NET syntax), ("N3") is a numeric format string that controls how numbers are displayed as strings.

Breaking Down "N3":
  • "N" stands for Number Format, which automatically adds thousands separators (commas).
  • "3" specifies that the number should be displayed with three decimal places.
Example Usage:
vb
CopyEdit
Dim myNumber As Double = 1234567.89123 Dim formattedNumber As String = myNumber.ToString("N3") MessageBox.Show(formattedNumber)
Output:
 
CopyEdit
1,234,567.891
Other Numeric Format Variations:Format Code Output Example (Value = 1234567.89123)
"N0"1,234,568 (No decimals, rounds up)
"N2"1,234,567.89 (Two decimal places)
"F3"1234567.891 (No thousands separator, fixed decimals)
"E2"1.23E+06 (Scientific notation, 2 decimals)

So, in iLogic, using "N3" ensures your mass, volume, or weight values are clearly formatted with thousands separators and three decimal places, making them more readable. 🚀

Message 14 of 14

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@chris , yeah to put that in place in your case, we'd would want to set and then update the parameters 

 

Then convert the WIP parameter back to a double (called WT in my example), then format it as a string using the N# as desired, and then hand it back to the iProperty with the suffix of  lbs

 

 

VIY = System.Math.Ceiling(iProperties.Volume / 46660) & " Yrds"
WIP = iProperties.Mass
RuleParametersOutput()
InventorVb.DocumentUpdate()


Dim WT As Double = WIP 
WTString = WT.ToString("N0")
iProperties.Value("Custom", "WIP") = WTString & " lbs"

iLogicVb.UpdateWhenDone = True

 

 

EESignature

0 Likes