Anonymous
1084 Views, 1 Reply
08-26-2020
05:18 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
08-26-2020
05:18 PM
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.
08-26-2020
10:58 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
08-26-2020
10:58 PM
Hi @Anonymous
I think this should be enough? ![]()
iLogicVb.UpdateWhenDone = True Dim oAsm As AssemblyDocument = ThisDoc.Document For Each oDoc As Document In oAsm.AllReferencedDocuments If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject AndAlso oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oDoc).Count > 0 For Each derComp As DerivedPartComponent In oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents derComp.BreakLinkToFile Next End If Next
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website