I need some assistance writing a piece of code

chris
Advisor

I need some assistance writing a piece of code

chris
Advisor
Advisor

I'm trying to add a custom parameter that includes a combination of parameter values, mostly "text" parameters, but at the end of that combination of text parameters I'd like to also include a numeric parameter and have it be formatted as Feet/fractional to 1/16th precision.

 

I'm not sure how to convert the numeric to a string as well as format it?

 

Example: (see image)

 

chris_0-1737392643865.png

 

0 Likes
Reply
Accepted solutions (1)
565 Views
24 Replies
Replies (24)

ryan.rittenhouse
Enthusiast
Enthusiast

You can format it as a fraction by calling FormatAsFraction(Geo_Length). I'd also recommend any time you are mixing numbers and strings to concatenate a string together, use '&' instead of '+' since it forces everything to be a string concat operation and you don't have to worry about it trying to add two numbers together.

 

To get feet and inches, you can do something like this:

 

Dim lengthInInches As Double = Geo_Length
Dim lengthInFeet As Integer = Floor(lengthInInches / 12)
lengthInInches -= lengthInFeet * 12
Dim lengthString As String = lengthInFeet & "' " & FormatAsFraction(lengthInInches) & """"

 

Then you can just put lengthString in place of Geo_Length in your iProperty 

0 Likes

mslosar
Advisor
Advisor

.ToString() should working in ilogic as well.

0 Likes

chris
Advisor
Advisor

@ryan.rittenhouse 

 

Thanks for the help, I applied what you wrote above along with the & to replace the +and everything except for the dimension formatting worked, it's as if IV defaults and pushes Inch decimal dimensions?

chris_0-1737409885936.png

 

0 Likes

chris
Advisor
Advisor

Here the code in the rule 

chris_1-1737412417642.png

 

0 Likes

Curtis_Waguespack
Consultant
Consultant

@chris, see example.

 

This exports and formats the param as a property, just like if you were to do this manually, and then uses the iprop in the string.

 

 

Dim oPart As PartDocument = ThisDoc.Document

'Dim oParam As UserParameter = oPart.ComponentDefinition.Parameters.ModelParameters.Item("Geo_Length")
Dim oParam As UserParameter = oPart.ComponentDefinition.Parameters.UserParameters.Item("Geo_Length")
Dim oProp As Inventor.Property

'export param as iprop and set formatting
oParam.ExposedAsProperty = True
oParam.CustomPropertyFormat.Units = UnitsTypeEnum.kInchLengthUnits
oParam.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
oParam.CustomPropertyFormat.ShowUnitsString = False

'get iprop
oProp = oPart.PropertySets.Item("Inventor User Defined Properties").Item(oParam.Name)

iProperties.Value("Custom", "Balloon_Cut_Length") = "Test String" & oProp.Value

 

 

 

Curtis_Waguespack_1-1737414779169.png

 

 

Curtis_Waguespack_0-1737414766169.png

0 Likes

chris
Advisor
Advisor

@Curtis_Waguespack Thanks for the help, yes I went ahead and added your code, and I did already have the custom property formatted for Feet, fraction 1/16th for that specific parameter, but even after adding and running your code, that dimension for that combo balloon data still only comes out as inches, decimal?

 

Here's what I am ultimatly trying to do, I'm attempting to add my "Stock Number" value to my parameter called Geo_Length to create a balloon style that shows both.

chris_0-1737416154800.png

 

chris_1-1737416181564.pngchris_2-1737416219406.png

 

 

Of course I can format my dimensions to be correct, I just don't understand why I can't get the custom formatting for the balloon

chris_0-1737417507846.png

 

0 Likes

chris
Advisor
Advisor

If anyone wants to jump on a quick zoom call I'm up for it, but text and screenshots are fine as well.

 

0 Likes

chris
Advisor
Advisor

Corrected by poster

 

 

0 Likes

J-Camper
Advisor
Advisor

@chris,

If you already have the Geo_Length exported as an iProperty, then you can include it in another iProperty by writing an equation into your Title iProperty.  Replace line 27 in the last screen shot you posted with this:

iProperties.Value("Summary", "Title") = "=" & B_Style & B_Size & "X" & B_Weight &"-CS - <Geo_Length> - LONG"

 

0 Likes

chris
Advisor
Advisor

Is there a way to make a balloon value be two or three lines instead of single long line of type/value?

Example:      

 

W10X22-CS

60.125" Long

128 lbs.

 

instead of 

 

W10X22-CS - (60.125" LONG) - 128 lbs.

0 Likes

J-Camper
Advisor
Advisor

@chris,

not through the native UI, but you can add carriage return line feeds, vbCrLf, to an iProperty with iLogic like this:

iProperties.Value("Summary", "Title") = "=" & B_Style & B_Size & "X" & B_Weight & "-CS" & vbCrLf & "<Geo_Length> - LONG"

MessageBox.Show(iProperties.Value("Summary", "Title"))
0 Likes

chris
Advisor
Advisor

@J-Camper Okay, the carriage return worked great, to build on that, can I then format everything within that lines of code to be text justified left or right, currently it is justifying everything centered? And I still haven't been able to solve the dimension showing up as Feet/Fractions, it only wants to stay Inch/decimal?

chris_0-1737482649131.png

 

0 Likes

J-Camper
Advisor
Advisor

@chris,

Formatting the balloons will need to be set in your styles manager, either modify the the existing style or create a new style for these specific balloons if you use ballooning for other things that want to maintain the centered formatting:

temp_png.png

 

As for the format of the iProperty "Geo_Length",  you should be getting whatever the custom iProperty format is set to.  In your reply to Curtis, I see you have an image showing the "Geo_Length_Balloon" Parameter/iProperty set to be feet fraction, but the code I posted is referencing the original "Geo_Length" Parameter/iProperty.  I don't think you need "Geo_Length_Balloon" Parameter at all, so I would delete it and format "Geo_Length" Parameter/iProperty the way you want.  Or you could change the code i posted to reference "Geo_Length_Balloon" if you want.

0 Likes

chris
Advisor
Advisor

@J-Camper  Yes, I noticed that to after I sent it, but "both" are formatted the way I'd like them to look, Foot/Fraction/1/16, but regardless of restarting, creating a new one or whatever, they still keep coming out as inch/decimal/3 places? (It's a mystery), IV does not like fractional stuff...

0 Likes

chris
Advisor
Advisor

@J-Camper I must be in a multiverse loop, because even though I have the correct text formatting, the balloon is not following?

You can see my frustration with this and the dimensioning formats, either are working the way they are supposed to...?

That's why I was trying to do an iLogic "over-ride" but perhaps it's just a IV bug?

chris_0-1737484377930.png

chris_1-1737484437055.png

 

 

0 Likes

J-Camper
Advisor
Advisor

I see.  I've never tried to force alignment on a balloon before, but it looks like it might be a limitation to with how balloons work.

I think the only way to get it close is by padding the lines to be the same length.  This heavily depends on the text you use though.  It would be simple with a text that has universal character width, but might not be exact using text with varied character width.

 

iProperties.Value("Custom", "Line1") = B_Style & B_Size & "X" & B_Weight & "-CS"
iProperties.Value("Custom", "Line2") = "=<Geo_Length> - LONG"

Dim PadLength As Integer = Max(iProperties.Value("Custom", "Line1").ToString.Length, iProperties.Value("Custom", "Line2").ToString.Length)

iProperties.Value("Summary", "Title") = iProperties.Value("Custom", "Line1").ToString.PadRight(PadLength, " ") & vbCrLf & iProperties.Value("Custom", "Line2").ToString.PadRight(PadLength, " ")

 

My test parameters & results:

temp_png.pngtemp_png2.png

0 Likes

chris
Advisor
Advisor

@J-Camper Can you do me a favor and try to get a dimension included in your example that is formatted to feet/Fraction/1/16 precision? I'd like to see if you are having the same issue I am, because I feel like Inventor 2025 is not working the way it is supposed to, as far as what should be simple formatting...

0 Likes

J-Camper
Advisor
Advisor

@chris,

I don't actually have 2025 installed on this machine.  My results have been coming from Inventor 2023. 

It definitely sounds like a bug to me if you have an iProperty formatted to feet fractions, but then the value string is providing a different format.  If that is the case you my have to use what Ryan posted first where you manually convert the value into a fraction from the parameter value.  Try this:

 

Dim lengthInInches As Double = Geo_Length
Dim lengthInFeet As Integer = Floor(lengthInInches / 12)
lengthInInches -= lengthInFeet * 12
Dim lengthString As String = lengthInFeet & "' " & FormatAsFraction(lengthInInches) & """"

Dim Line1 As String = B_Style & B_Size & "X" & B_Weight & "-CS"
Dim Line2 As String = lengthString & " - LONG"

Dim PadLength As Integer = Max(Line1.Length, Line2.Length)

iProperties.Value("Summary", "Title") = Line1.PadRight(PadLength, " ") & vbCrLf & Line2.PadRight(PadLength, " ")

 

The reason this didn't work for you earlier, your reply to Ryan on 01-20-2025 05:33 PM, was because you did not use the "lengthString" ObjectVariable created in Ryan's code.  Your image shows Ryan's code and then your property is just using the parameter value itself instead of the manually converted string.

0 Likes

chris
Advisor
Advisor

@J-Camper That last bit of code worked! Awesome, thank you for the help!

 

chris_0-1737504747229.png

 

0 Likes