Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

 

@harvey3ELEA, using the previous example, see the additions in blue

 

I don't think the Apply to existing... checkbox is applicable here, as it we wouldn't do that via automation... or at least I don't know how to programmatically select that

 

Sub Main

	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences

	'step into sub with the target occurrence being the the top level assembly
	Call TraverseAssembly(oOccs)

End Sub

Sub TraverseAssembly(oOccs As ComponentOccurrences)

	Dim oOcc As ComponentOccurrence
	For Each oOcc In oOccs

		If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			'step back into this sub with the target occurrence being the subassembly
			Call TraverseAssembly(oOcc.SubOccurrences)
		Else 'parts

			Dim partDoc As PartDocument = oOcc.Definition.Document

			If Not partDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For' Check if sheet metal part

			'step into sub routine
			Call FlatExtents(partDoc)
		End If
	Next

End Sub


Sub FlatExtents(partDoc As PartDocument)

	Dim oCompDef As SheetMetalComponentDefinition = partDoc.ComponentDefinition

	If oCompDef.HasFlatPattern = False Then
		oCompDef.Unfold
		oCompDef.FlatPattern.ExitEdit
	End If

	oA = oCompDef.FlatPattern.Length
	oB = oCompDef.FlatPattern.Width

	oFlat_Length = Max(oA, oB)
	oFlat_Wdith = Min(oA, oB)

	' Get the parameters of the component definition
	Dim params As Parameters = oCompDef.Parameters

	' Check if parameters "DIMA" and "DIMB" exist, update or add them
	Try
		params.UserParameters.Item("DIMA").Value = oFlat_Length
	Catch
		params.UserParameters.AddByValue("DIMA", oFlat_Length, "in")
	End Try
	Try
		params.UserParameters.Item("DIMB").Value = oFlat_Wdith
	Catch
		params.UserParameters.AddByValue("DIMB", oFlat_Wdith, "in")
	End Try

	' Set parameters to be exposed as properties
	params.Item("DIMA").ExposedAsProperty = True
	params.Item("DIMA").CustomPropertyFormat.Units = UnitsTypeEnum.kInchLengthUnits
	params.Item("DIMA").CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
	params.Item("DIMA").CustomPropertyFormat.ShowUnitsString = False

	params.Item("DIMB").ExposedAsProperty = True
	params.Item("DIMB").CustomPropertyFormat.Units = UnitsTypeEnum.kInchLengthUnits
	params.Item("DIMB").CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
	params.Item("DIMB").CustomPropertyFormat.ShowUnitsString = False

	iProperties.Value(partDoc.DisplayName, "Custom", "DIMA") = "=<Sheet Metal Length>"
	iProperties.Value(partDoc.DisplayName, "Custom", "DIMB") = "=<Sheet Metal Width>"

End Sub