Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
J-Camper
in reply to: DewayneH

You should be able to change the Trys to be less specific and look through all Parameters instead of all User Parameters:

 

Sub Main
If ThisApplication.ActiveDocument.DocumentType = kPartDocumentObject Or ThisApplication.ActiveDocument.DocumentType = kAssemblyDocumentObject Then Else Exit Sub
Dim openDoc As Document = ThisApplication.ActiveDocument
'Look at all of the files referenced in the open document
Dim docFile As Document
If openDoc.DocumentType = kPartDocumentObject
	Call Formatting(openDoc) 
Else
	For Each docFile In openDoc.AllReferencedDocuments
		'look at only part files that are modifiable
    	If docFile.DocumentType = kPartDocumentObject And docFile.IsModifiable = True
			Call Formatting(docFile)
		End If
	Next 
End If
iLogicVb.UpdateWhenDone = True
End Sub

Sub Formatting(oDoc As PartDocument)
	'[
	'For Thickness Parameter
	Try
		oThickness = oDoc.ComponentDefinition.Parameters.Item("Thickness")
	Catch
		oThickness = oDoc.ComponentDefinition.Parameters.UserParameters.AddByValue("Thickness", 1, "in")
	End Try	
	oThickness.ExposedAsProperty = True
	If oThickness.Units = "mm"
		oFormat=oThickness.CustomPropertyFormat
		oFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType
		oFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
		oFormat.Units = "mm"
		oFormat.ShowUnitsString = True
		oFormat.ShowLeadingZeros = False
		oFormat.ShowTrailingZeros = True
		
	Else If oThickness.Units = "in"
		oFormat=oThickness.CustomPropertyFormat
		oFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType
		oFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kThreeDecimalPlacesPrecision
		oFormat.Units = "in"
		oFormat.ShowUnitsString = False
		oFormat.ShowLeadingZeros = False
		oFormat.ShowTrailingZeros = True
	
	End If
	'] For Thickness Parameter
	
	'[
	'For Width Parameter
	Try
		oWidth = oDoc.ComponentDefinition.Parameters.Item("Width")
	Catch
		oWidth = oDoc.ComponentDefinition.Parameters.UserParameters.AddByValue("Width", 15, "in")
	End Try	
	oWidth.ExposedAsProperty = True
	If oWidth.Units = "mm"
		oFormat=oWidth.CustomPropertyFormat
		oFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType
		oFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
		oFormat.Units = "mm"
		oFormat.ShowUnitsString = True
		oFormat.ShowLeadingZeros = False
		oFormat.ShowTrailingZeros = True
		
	Else If oWidth.Units = "in"
		oFormat=oWidth.CustomPropertyFormat
		oFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType
		oFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kThreeDecimalPlacesPrecision
		oFormat.Units = "in"
		oFormat.ShowUnitsString = False
		oFormat.ShowLeadingZeros = False
		oFormat.ShowTrailingZeros = True
	
	End If
	'] For Width Parameter
	
	'[
	'For Length Parameter
	Try
		oLength = oDoc.ComponentDefinition.Parameters.Item("Length")
	Catch
		oLength = oDoc.ComponentDefinition.Parameters.UserParameters.AddByValue("Length", 45, "in")
	End Try	
	oLength.ExposedAsProperty = True
	If oLength.Units = "mm"
		oFormat=oLength.CustomPropertyFormat
		oFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType
		oFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
		oFormat.Units = "mm"
		oFormat.ShowUnitsString = True
		oFormat.ShowLeadingZeros = False
		oFormat.ShowTrailingZeros = True
		
	Else If oLength.Units = "in"
		oFormat=oLength.CustomPropertyFormat
		oFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType
		oFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kThreeDecimalPlacesPrecision
		oFormat.Units = "in"
		oFormat.ShowUnitsString = False
		oFormat.ShowLeadingZeros = False
		oFormat.ShowTrailingZeros = True
	
	End If
	'] For Length Parameter
	oDoc.Rebuild
End Sub