Ilogic for replacement

Ilogic for replacement

mingzhuoou
Participant Participant
526 Views
2 Replies
Message 1 of 3

Ilogic for replacement

mingzhuoou
Participant
Participant

Hi,

I have an assembly model and I want to use ilogic to replace all sub-ass and parts which I just rename by manual in local. Such as an old name "df-o-abc-part-1234.ipt" rename to "df-m-xyz-part-1234", I want to resovle the assembly by using ilogic that find the new name parts automatically, and in this assembly model there are a lot of parts such like this and also rename by the same rules. Could you give some idea for me? Thank you!

0 Likes
527 Views
2 Replies
Replies (2)
Message 2 of 3

Xun.Zhang
Alumni
Alumni

Hello @mingzhuoou,

Here is a VBA example to replace the file.

Hope it helps!

Sub Main()

    'Component.Replace( "df-o-abc-part-1234.ipt","df-m-xyz-part-1234.ipt", True)

    Dim doc As AssemblyDocument
    doc = ThisApplication.ActiveDocument

    Dim strFileName As String
    strFileName = "df-o-abc-part-1234:"

    Dim strPath As String
    strPath = "C:\TEMP\iLogicTest\GA\df-m-xyz-part-1234.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

 


Xun
Message 3 of 3

mingzhuoou
Participant
Participant

Hi, @Xun.Zhang

Thank you for your quick replay, may I havn't describe the correct request, what I want is that there is several parts in assembly, and there are have a same naming rules like "df-o-abc-part-1234.ipt" , "df-o-abc-part-4567.ipt" but the last numbers in name is random, so I want to get the red text and replace by other text and replace by those by parts.

0 Likes