Not applicable
08-26-2020
05:18 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
i am writing an iLogic script to run from a top level assembly that will go through all sub assemblies and their respective parts and break the link to all components that have a link to a base component.
This is what i have so far but it just keeps locking up and crashing my Inventor 2021
Sub Main() Dim assm As AssemblyDocument assm = ThisApplication.ActiveDocument Dim occ As ComponentOccurrence Dim derpart As DerivedPartComponent Dim partdoc As PartDocument 'it f you want to use all components' Dim doc As AssemblyDocument = ThisDoc.Document Dim oLOD As LevelOfDetailRepresentation Dim oAsmCompDef As ComponentDefinition oAsmCompDef = doc.ComponentDefinition Try oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Master").Activate(True) Catch Dim nLOD As LevelOfDetailRepresentation nLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add("Master") oLOD = nLOD Finally oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Master").Activate(True) End Try For Each occ In assm.ComponentDefinition.Occurrences If occ.DefinitionDocumentType = kPartDocumentObject Then For Each derpart In occ.Definition.ReferenceComponents.DerivedPartComponents derpart.BreakLinkToFile iLogicVb.UpdateWhenDone = True Next ElseIf occ.DefinitionDocumentType = kAssemblyDocumentObject Then Call processAllSubOcc(occ) ' subassembly End If Next End Sub '' This function is called for processing sub assembly. It is called recursively '' to iterate through the entire assembly tree. Sub processAllSubOcc(ByRef occ As ComponentOccurrence) Dim derpart As DerivedPartComponent Dim oSubCompOcc As ComponentOccurrence For Each oSubCompOcc In occ.SubOccurrences ' Check if it's child occurrence (leaf node) If oSubCompOcc.DefinitionDocumentType = kPartDocumentObject Then For Each derpart In oSubCompOcc.Definition.ReferenceComponents.DerivedPartComponents 'My Code derpart.BreakLinkToFile iLogicVb.UpdateWhenDone = True Next ElseIf occ.DefinitionDocumentType = kAssemblyDocumentObject Then Call processAllSubOcc(occ) ' subassembly End If Next End Sub
Solved! Go to Solution.