Format Specific Exported Parameters from Assembly Level

Format Specific Exported Parameters from Assembly Level

DewayneH
Advocate Advocate
790 Views
6 Replies
Message 1 of 7

Format Specific Exported Parameters from Assembly Level

DewayneH
Advocate
Advocate

 

I need to format the Thickness, Width, and Length parameters on a group of parts from the assembly level.

I know this has been done, and I found what I though were many solutions, none of which worked. At least I was able to screw it up. I'm finally at a point it looks like the rule is running, but nothing is changing. 

 

I need to verify the rule is running only on parts that are modifiable. I'd also like the rule to run if is executed in a part file.

I've attached my latest failure.

 

 

 

 

Dewayne
Inventor Pro 2023
Vault Pro 2023
0 Likes
Accepted solutions (1)
791 Views
6 Replies
Replies (6)
Message 2 of 7

bradeneuropeArthur
Mentor
Mentor

What would you exactly like to do?

Could you explain it step by step?

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 7

J-Camper
Advisor
Advisor

I believe this is working as you want, not too different from what you posted:

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.UserParameters.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.UserParameters.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.UserParameters.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

I put the formatting into a subroutine to make handling the different document types easier in the main routine. 

0 Likes
Message 4 of 7

DewayneH
Advocate
Advocate

 

The rule would format the exported Thickness, Width, and Length parameters based on the parameters units, "in" or "mm".

 

For example:

 

If oThickness.Units = "mm" Then
                        
                            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"  Then
                        
                            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

 

If the rule runs in a part file the parameters would be formatted as shown based on the units.

 

If the rule runs in an assembly file, the parameters in all the parts would be formatted. 

If the part is modifiable.

 

 

Dewayne
Inventor Pro 2023
Vault Pro 2023
0 Likes
Message 5 of 7

DewayneH
Advocate
Advocate

 

That is almost exactly what I need.

The thing I didn't account for is, in some files the parameters may not be user parameters. Sometimes they can be model parameters. In those cases the rule recreates the parameter as a user parameter and the intended parameter doesn't get formatted.

For example if "Thickness" is a model parameter it won't be formatted, and "Thickness_1" will be created and formatted as a user parameter.

How can it be written to format the existing model parameter and not recreate it?

Dewayne
Inventor Pro 2023
Vault Pro 2023
0 Likes
Message 6 of 7

J-Camper
Advisor
Advisor
Accepted solution

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

 

0 Likes
Message 7 of 7

DewayneH
Advocate
Advocate

 

That did it. Works like a charm.

Thanks for the help. 

Dewayne
Inventor Pro 2023
Vault Pro 2023
0 Likes