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

iLogic component replace within nested subassemblies

Anonymous

iLogic component replace within nested subassemblies

Anonymous
Not applicable

To start off, I'm new to iLogic.

I'm looking to replace all ipt files of a certain name with my own file. I believe I have a working ilogic rule that allows me to do just that. My problem is this rule only works within a single iam file, searching for an ipt and replacing it. I need this rule to propagate from a high level assembly and search all assembly files, sometimes two or three tier nested assemblies.

 

This is what I've managed to come up with that seems to work within a single assembly file.

 

 

 

oOccurrences = ThisDoc.Document.ComponentDefinition.Occurrences

For Each oComp As ComponentOccurrence In oOccurrences
    oCompName = oComp.Name
    If InStr(oCompName, "PnC") > 0 Then
        Component.Replace(oCompName,"Weld.ipt", True)
    End If
Next    

 

0 Likes
Reply
924 Views
2 Replies
Replies (2)

Xun.Zhang
Alumni
Alumni

Try the sample below via API. 

Replace all sub assembly which include Collar.ipt and replace it.

 

Sub Main()

    'Component.Replace("CollarBottomPlate:1", "Collar.ipt", True)

    Dim doc As AssemblyDocument

    doc = ThisApplication.ActiveDocument

    Dim strFileName As String

    strFileName = "Collar:"

    Dim strPath As String

    strPath = "C:\TEMP\iLogicTest\GA\CollarBottomPlate.ipt"

    

    Dim oOcc As ComponentOccurrence

    For Each oOcc In doc.ComponentDefinition.Occurrences

        Call ReplaceOccurrence(strFileName, strPath, oOcc)

    Next

End Sub



Sub ReplaceOccurrence(strFileName As String, strPath As String, oOcc As ComponentOccurrence)

    If InStr(oOcc.Name,strFileName)>0 Then

        Call oOcc.Replace(strPath, False)

    End If

    Dim osubOcc As ComponentOccurrence

    If oOcc.SubOccurrences.Count > 0 Then

        For Each osubOcc In oOcc.SubOccurrences

            Call ReplaceOccurrence(strFileName, strPath, osubOcc)

        Next

    End If

End Sub

another example like to replace Collar.ipt in every assembly

 

Sub Main()

    'Component.Replace("CollarBottomPlate:1", "Collar.ipt", True)

    Dim doc As AssemblyDocument

    doc = ThisApplication.ActiveDocument

    Dim strFileName As String

    strFileName = "Collar:1"

    Dim strPath As String

    strPath = "C:\TEMP\iLogicTest\GA\CollarBottomPlate.ipt"

    Dim oOcc As ComponentOccurrence

    For Each oOcc In doc.ComponentDefinition.Occurrences

        Call ReplaceOccurrence(strFileName, strPath, oOcc)

    Next

End Sub



Sub ReplaceOccurrence(strFileName As String, strPath As String, oOcc As ComponentOccurrence)

    If oOcc.Name = strFileName Then

        Call oOcc.Replace(strPath, False)

    End If

    Dim osubOcc As ComponentOccurrence

    If oOcc.SubOccurrences.Count > 0 Then

        For Each osubOcc In oOcc.SubOccurrences

            Call ReplaceOccurrence(strFileName, strPath, osubOcc)

        Next

    End If

End Sub

Hope it helps!

 


Xun
0 Likes

Anonymous
Not applicable

I can see how this would work for a simple single file with a known file path. I've been trying to figure out a way to alter this to work for me.

 

an example of the file names I have would be "PnC_Geometry_Spot_80000_01_R"

The "80000_01" would be different for each file.

I would have to keep an "If InStr" condition to call out only a portion of the file name, with each "PnC" file path unknown.

 

I think the last example I received may be a helpful template and I'll keep playing with it and see what I can come up with.

Thanks for the help so far!

0 Likes