Removing leading zero in custom properties

Removing leading zero in custom properties

M_Santi
Enthusiast Enthusiast
679 Views
4 Replies
Message 1 of 5

Removing leading zero in custom properties

M_Santi
Enthusiast
Enthusiast

I have my custom properties linked to my parameter and I'm trying to find a way to remove the leading zero. 

How would I code it into ilogic? My drawing template is not liked to any part or assembly.

 

Mikail_Santi_0-1674829568320.png

Mikail_Santi_2-1674830047805.png

 

 

 

 

0 Likes
Accepted solutions (1)
680 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @M_Santi.  When setting up your 'Custom Property Format' settings manually, as shown in your image...if you leave the 'Units' set to 'Text', then you can simply un-check the checkbox next to the 'Leading Zeros' setting.  But if you change the 'Units' to Number, instead of Text, then the leading zero is already being removed, by default.  There are ways to set all of those same settings by code too, if you would prefer to do it that way.  I assume that these source parameters have been created directly within the drawing document then, right?

Here is an iLogic rule you can try out.  This rule will ensure that those parameters exist, and are set to the values, units, and custom property format settings that you want.

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing document must be active for this code to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisDoc.Document
	Dim oParamsToCreate As New List(Of String())
	oParamsToCreate.Add({"AREA", ".29878 in^2", "in^2"})
	oParamsToCreate.Add({"MASS", ".358 lbmass", "lbmass"})
	Dim oUParams As UserParameters = oDDoc.Parameters.UserParameters
	Dim oUParam As UserParameter = Nothing
	For Each Entry In oParamsToCreate
		Dim oName As String = Entry(0)
		Dim oExpression As String = Entry(1)
		Dim oUnits As String = Entry(2)
		Try
			oUParam = oUParams.Item(oName)
			oUParam.Units = oUnits
			oUParam.Expression = oExpression
		Catch
			oUParam = oUParams.AddByExpression(oName, oExpression, oUnits)
		End Try
		Try
			oUParam.ExposedAsProperty = True
			Dim oCPF As CustomPropertyFormat = oUParam.CustomPropertyFormat
			oCPF.PropertyType = CustomPropertyTypeEnum.kTextPropertyType
			oCPF.Units = oUParam.Units
			oCPF.Precision = CustomPropertyPrecisionEnum.kThreeDecimalPlacesPrecision
			oCPF.ShowUnitsString = False
			oCPF.ShowLeadingZeros = False
			oCPF.ShowTrailingZeros = True
		Catch : End Try
	Next
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

M_Santi
Enthusiast
Enthusiast

It still shows the leading zero. Also What I'm trying to accomplish for this is that the MASS = AREA * 1.2. I want AREA to be manually put in. My main problem with it is that the leading zero keep showing up. I am also having with trailing 0 not showing up.

 

Mikail_Santi_0-1674840864391.png

 

 

 

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

Hmm... That does seem a bit odd that even when you have the settings set the way you want them, you are still seeing those values out in your form not looking like the 'preview'.  I have encountered this scenario too on occasion, but I can usually fix it by un-checking the checkbox in the 'Export Parameter' column, then checking it again, then going back into the Custom Property Format dialog and setting it back to the way I wanted it to be.  There seems to be an update of some sort needed sometimes, to refresh the associated custom iProperties formatting after changes have been made.  Anyways, here is a simplified version of the last code I posted.  It no longer attempts to create, or update the AREA parameter, but does check that it exists, and if it does not exist yet, it lets you know, then exits the rule.  It then checks for the MASS parameter, and if not found, creates it, using the equation you specified.  Then, since I needed to use the same block twice (once for each of the 2 parameters), I put the code for setting the custom property format stuff out into a separate Sub routine that I could call once for each parameter.  I also included a line at the end of the Sub Main area to update the drawing document.  Hopefully that will help some.

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing document must be active for this code to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisDoc.Document
	Dim oUParams As UserParameters = oDDoc.Parameters.UserParameters
	Dim oAreaParam As UserParameter = Nothing
	Try
		oAreaParam = oUParams.Item("AREA")
	Catch
		MsgBox("Parameter named 'AREA' not found!", vbCritical, "")
		Exit Sub
	End Try
	SetCustomPropertyFormat(oAreaParam)
	Dim oMassParam As UserParameter = Nothing
	Try
		oMassParam = oUParams.Item("MASS")
		oMassParam.Units = "ul"
		oMassParam.Expression = "AREA * 1.2 ul"
	Catch
		oMassParam = oUParams.AddByExpression("MASS", "AREA * 1.2 ul", "ul")
	End Try
	SetCustomPropertyFormat(oMassParam)
	oDDoc.Update
End Sub

Sub SetCustomPropertyFormat(oParam As Inventor.Parameter)
	Try
		oParam.ExposedAsProperty = True
		Dim oCPF As CustomPropertyFormat = oParam.CustomPropertyFormat
		oCPF.PropertyType = CustomPropertyTypeEnum.kTextPropertyType
		oCPF.Units = "ul"
		oCPF.Precision = CustomPropertyPrecisionEnum.kThreeDecimalPlacesPrecision
		oCPF.ShowUnitsString = False
		oCPF.ShowLeadingZeros = False
		oCPF.ShowTrailingZeros = True
	Catch
		MsgBox("SetCustomPropertyFormat failed!", vbExclamation, "")
	End Try
End Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

M_Santi
Enthusiast
Enthusiast
Accepted solution

I was able to figure it out. All I had to do was to make sure that on custom properties that the type is "text" on it while on the parameters it is on numeric. 

 

Mikail_Santi_0-1674843337772.png

Mikail_Santi_1-1674843352280.png

 

 

0 Likes