<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: iLogic component replace within nested subassemblies in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-component-replace-within-nested-subassemblies/m-p/8033923#M84856</link>
    <description>&lt;P&gt;Try the sample below via API.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Replace all sub assembly which include Collar.ipt and replace it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;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)&amp;gt;0 Then

        Call oOcc.Replace(strPath, False)

    End If

    Dim osubOcc As ComponentOccurrence

    If oOcc.SubOccurrences.Count &amp;gt; 0 Then

        For Each osubOcc In oOcc.SubOccurrences

            Call ReplaceOccurrence(strFileName, strPath, osubOcc)

        Next

    End If

End Sub&lt;/PRE&gt;
&lt;P&gt;another example like to replace Collar.ipt in every assembly&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;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 &amp;gt; 0 Then

        For Each osubOcc In oOcc.SubOccurrences

            Call ReplaceOccurrence(strFileName, strPath, osubOcc)

        Next

    End If

End Sub&lt;/PRE&gt;
&lt;P&gt;Hope it helps!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 30 May 2018 00:40:03 GMT</pubDate>
    <dc:creator>Xun.Zhang</dc:creator>
    <dc:date>2018-05-30T00:40:03Z</dc:date>
    <item>
      <title>iLogic component replace within nested subassemblies</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-component-replace-within-nested-subassemblies/m-p/8033422#M84855</link>
      <description>&lt;P&gt;To start off, I'm new to iLogic.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I've managed to come up with that seems to work within a single assembly file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;oOccurrences = ThisDoc.Document.ComponentDefinition.Occurrences&lt;BR /&gt;&lt;BR /&gt;For Each oComp As ComponentOccurrence In oOccurrences&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;oCompName = oComp.Name&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;If InStr(oCompName, "PnC") &amp;gt; 0 Then&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Component.Replace(oCompName,"Weld.ipt", True)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;End If&lt;BR /&gt;Next&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 20:02:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-component-replace-within-nested-subassemblies/m-p/8033422#M84855</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-05-29T20:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic component replace within nested subassemblies</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-component-replace-within-nested-subassemblies/m-p/8033923#M84856</link>
      <description>&lt;P&gt;Try the sample below via API.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Replace all sub assembly which include Collar.ipt and replace it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;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)&amp;gt;0 Then

        Call oOcc.Replace(strPath, False)

    End If

    Dim osubOcc As ComponentOccurrence

    If oOcc.SubOccurrences.Count &amp;gt; 0 Then

        For Each osubOcc In oOcc.SubOccurrences

            Call ReplaceOccurrence(strFileName, strPath, osubOcc)

        Next

    End If

End Sub&lt;/PRE&gt;
&lt;P&gt;another example like to replace Collar.ipt in every assembly&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;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 &amp;gt; 0 Then

        For Each osubOcc In oOcc.SubOccurrences

            Call ReplaceOccurrence(strFileName, strPath, osubOcc)

        Next

    End If

End Sub&lt;/PRE&gt;
&lt;P&gt;Hope it helps!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 00:40:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-component-replace-within-nested-subassemblies/m-p/8033923#M84856</guid>
      <dc:creator>Xun.Zhang</dc:creator>
      <dc:date>2018-05-30T00:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic component replace within nested subassemblies</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-component-replace-within-nested-subassemblies/m-p/8034902#M84857</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;an example of the file names I have would be "PnC_Geometry_Spot_80000_01_R"&lt;/P&gt;&lt;P&gt;The "80000_01" would be different for each file.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Thanks for the help so far!&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 11:17:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-component-replace-within-nested-subassemblies/m-p/8034902#M84857</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-05-30T11:17:26Z</dc:date>
    </item>
  </channel>
</rss>

