Change format of exported parameter to fractional with iLogic

Change format of exported parameter to fractional with iLogic

karthur1
Mentor Mentor
715 Views
3 Replies
Message 1 of 4

Change format of exported parameter to fractional with iLogic

karthur1
Mentor
Mentor

I am trying to write a code that will change the format of an existing exported parameter.  I want the format to be FRACTIONAL 1/32 precision.  I have found several code examples around that change the format to decimalxplaces format.  I can get the code to work fine with DECIMAL formatting, but when I try to use the suggested code for fractional formatting (suggested by the iLogic) I get an error.

 

2019-06-12_0941.png

 

Not sure what I am going wrong.  See attached Code.

 

Any help as to what the correct code should be to get the parameter to be FRACTIONAL One ThirtySecond precision?

 

Kirk

 

0 Likes
716 Views
3 Replies
Replies (3)
Message 2 of 4

Sergio.D.Suárez
Mentor
Mentor

Hi, What Inventor Version do you have? I tested your code in 2018 and I really could not do anything. Then try Inv 2020 and I do it without problems, trying to see if there is any document file property or other configuration that gives me problems. I attached the file in Inv 2020. Regards

 

Dim partDoc As PartDocument = ThisDoc.Document
Dim userParams As UserParameters = partDoc.ComponentDefinition.Parameters.UserParameters

oLength = userParams("Cutlength")
oLength.ExposedAsProperty = True
oFormat=oLength.CustomPropertyFormat
oFormat.PropertyType = Inventor.CustomPropertyTypeEnum.kTextPropertyType

oFormat.Units="in"
oFormat.ShowUnitsString=False
oFormat.ShowTrailingZeros = False
oFormat.ShowLeadingZeros = False
oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kThirtySecondsFractionalLengthPrecision

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 4

karthur1
Mentor
Mentor

I am using 2018, but I also have 202 loaded... just have not made the switch yet.

 

I see now why I was getting the error.  The line where I am setting the format to fractional 1/32 precision works fine.  The problem is that I am also trying to set .ShowTrailingZero =False and .ShowLeadingZeros=False.  Those two are not available when the fractional format is selected.

This now works for the Fractional 1/32 precision.

 

Dim partDoc As PartDocument = ThisDoc.Document
Dim userParams As UserParameters = partDoc.ComponentDefinition.Parameters.UserParameters

oLength = userParams("Cutlength")
oLength.ExposedAsProperty = True
oFormat=oLength.CustomPropertyFormat
oFormat.PropertyType = Inventor.CustomPropertyTypeEnum.kTextPropertyType

oFormat.Units="in"
oFormat.ShowUnitsString = False
oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kThirtySecondsFractionalLengthPrecision
'oFormat.ShowTrailingZeros = False
'oFormat.ShowLeadingZeros = False

 

Thanks.

Kirk

Message 4 of 4

Sergio.D.Suárez
Mentor
Mentor

You're right, I've already noticed the problem.
Take your original code, the first error is what you describe above, and second that you must first define the unit "in" before placing fractional, because in mm that option is not found. I just moved the lines so that it looks like the code works.
regards

 

Dim partDoc As PartDocument = ThisDoc.Document
Dim userParams As UserParameters = partDoc.ComponentDefinition.Parameters.UserParameters

oLength = Parameter.Param("Cutlength")
oLength.ExposedAsProperty = True
oFormat=oLength.CustomPropertyFormat
oFormat.PropertyType = Inventor.CustomPropertyTypeEnum.kTextPropertyType
'	Set format as Decimal - three place precision
'oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kThreeDecimalPlacesPrecision
' 	Set precision as Fractional - 1/32 precision



oFormat.ShowUnitsString=False
'set to show/not show the unit string (use True to show)
oFormat.ShowUnitsString=False
'set to show/not show the trailing zeros (use True to show)
oFormat.ShowTrailingZeros = False
'set to show/not show the leading zeros (use True to show)
oFormat.ShowLeadingZeros = False



oFormat.Units="in"
oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kThirtySecondsFractionalLengthPrecision

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes