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

I have come up with the following code which works fine but I hate the fact that I have to hard code the names of each parent bolt in component.replace command. See the code below.

 

Dim oDoc As AssemblyDocument
    oDoc = ThisApplication.ActiveDocument
 
Dim oPattern As OccurrencePattern
    oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("BR STRING FASTENER SET")
    
Dim oElement As OccurrencePatternElement
    oElements = oPattern.OccurrencePatternElements

Dim i As Integer
For i = 1 To oElements.Count
    Dim OCCS As OccurrencePatternElement
        OCCS = oElements(i).Components(1).OccurrencePatternElements(1)
        
    For Each OCCS In oElements
        Try
            Component.Replace("BR BOLT 1", "File name to replace with including path", False)
            Component.Replace("BR BOLT 2", "File name to replace with including path", False)
            Component.Replace("BR BOLT 3", "File name to replace with including path", False)
        Catch
            'some code here
End Try Next Next InventorVb.DocumentUpdate()

 

As I understand, this code is replacing only the parent or master component. The rest of the occurrances are replaced or updated due to fact that they are the pattern of this master component. In this case the master components are 3 bolts.

 

Anyway it works!!

 

Cheers