06-19-2024
11:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
06-19-2024
11:06 AM
@_bmiller_ , give this a try ( I didn't test it well, but it should work)
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 oFlat_Length = oCompDef.FlatPattern.Length oFlat_Wdith = oCompDef.FlatPattern.Width ' 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.AddByExpression("DIMA", oFlat_Length, "in") End Try Try params.UserParameters.Item("DIMB").Expression = oFlat_Wdith Catch params.UserParameters.AddByExpression("DIMB", oFlat_Wdith, "in") End Try ' Set parameters to be exposed as properties params.Item("DIMA").ExposedAsProperty = True params.Item("DIMB").ExposedAsProperty = True iProperties.Value(partDoc.DisplayName, "Custom", "DIMA") = "=<Sheet Metal Length>" iProperties.Value(partDoc.DisplayName, "Custom", "DIMB") = "=<Sheet Metal Width>" End Sub