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

iLogic - Break link to all base components from Top level assembly

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
JhoelForshav
in reply to: Anonymous

Hi @Anonymous 

I think this should be enough? :slightly_smiling_face:

 

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