<?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 for Save and Replace within an assembly by part name in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-for-save-and-replace-within-an-assembly-by-part-name/m-p/11100728#M136637</link>
    <description>&lt;P&gt;This should be what your looking for. First it goes through all reference docs and selects one with "cube.ipt" in its file path. Then it creates a copy of that naming it "my_custom_name". Then it makes a privite event to skip the dialog box. Then it runs the replace all cmd. Finally it refreshes the browser nodes.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oAss&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;AssemblyDocument&lt;/SPAN&gt;
&lt;SPAN&gt;oAss&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;ActiveDocument&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oDoc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Document&lt;/SPAN&gt;
&lt;SPAN&gt;For&lt;/SPAN&gt; &lt;SPAN&gt;Each&lt;/SPAN&gt; &lt;SPAN&gt;oDoc&lt;/SPAN&gt; &lt;SPAN&gt;In&lt;/SPAN&gt; &lt;SPAN&gt;oAss&lt;/SPAN&gt;.&lt;SPAN&gt;AllReferencedDocuments&lt;/SPAN&gt;
	&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;InStr&lt;/SPAN&gt;(&lt;SPAN&gt;oDoc&lt;/SPAN&gt;.&lt;SPAN&gt;FullDocumentName&lt;/SPAN&gt;, &lt;SPAN&gt;"cube.ipt"&lt;/SPAN&gt;) &amp;gt; 0
		&lt;SPAN&gt;template&lt;/SPAN&gt; = &lt;SPAN&gt;oDoc&lt;/SPAN&gt;.&lt;SPAN&gt;FullDocumentName&lt;/SPAN&gt;
		&lt;SPAN&gt;newlength&lt;/SPAN&gt; = &lt;SPAN&gt;InStrRev&lt;/SPAN&gt;(&lt;SPAN&gt;oDoc&lt;/SPAN&gt;.&lt;SPAN&gt;FullDocumentName&lt;/SPAN&gt;, &lt;SPAN&gt;"\"&lt;/SPAN&gt;)
		&lt;SPAN&gt;newfile&lt;/SPAN&gt; = &lt;SPAN&gt;Left&lt;/SPAN&gt;(&lt;SPAN&gt;template&lt;/SPAN&gt;, &lt;SPAN&gt;newlength&lt;/SPAN&gt;) &amp;amp; &lt;SPAN&gt;"my_custom_name.ipt"&lt;/SPAN&gt;
		&lt;SPAN&gt;IO&lt;/SPAN&gt;.&lt;SPAN&gt;File&lt;/SPAN&gt;.&lt;SPAN&gt;Copy&lt;/SPAN&gt;(&lt;SPAN&gt;template&lt;/SPAN&gt;, &lt;SPAN&gt;newfile&lt;/SPAN&gt;, &lt;SPAN&gt;True&lt;/SPAN&gt;)

		&lt;SPAN&gt;oDocName&lt;/SPAN&gt; = &lt;SPAN&gt;System&lt;/SPAN&gt;.&lt;SPAN&gt;IO&lt;/SPAN&gt;.&lt;SPAN&gt;Path&lt;/SPAN&gt;.&lt;SPAN&gt;GetFileNameWithoutExtension&lt;/SPAN&gt;(&lt;SPAN&gt;oDoc&lt;/SPAN&gt;.&lt;SPAN&gt;FullDocumentName&lt;/SPAN&gt;)
&lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;CommandManager&lt;/SPAN&gt;.&lt;SPAN&gt;PostPrivateEvent&lt;/SPAN&gt;(&lt;SPAN&gt;PrivateEventTypeEnum&lt;/SPAN&gt;.&lt;SPAN&gt;kFileNameEvent&lt;/SPAN&gt;, &lt;SPAN&gt;newfile&lt;/SPAN&gt;)
		&lt;SPAN&gt;compo&lt;/SPAN&gt; = &lt;SPAN&gt;Component&lt;/SPAN&gt;.&lt;SPAN&gt;InventorComponent&lt;/SPAN&gt;(&lt;SPAN&gt;oDocName&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;":1"&lt;/SPAN&gt;)
		&lt;SPAN&gt;oAss&lt;/SPAN&gt;.&lt;SPAN&gt;SelectSet&lt;/SPAN&gt;.&lt;SPAN&gt;Select&lt;/SPAN&gt;(&lt;SPAN&gt;compo&lt;/SPAN&gt;)
			
		
		&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oReplaceCmd&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;ControlDefinition&lt;/SPAN&gt;
		&lt;SPAN&gt;oReplaceCmd&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;CommandManager&lt;/SPAN&gt;.&lt;SPAN&gt;ControlDefinitions&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;"AssemblyReplaceAllCmd"&lt;/SPAN&gt;)
		&lt;SPAN&gt;oReplaceCmd&lt;/SPAN&gt;.&lt;SPAN&gt;Execute&lt;/SPAN&gt;
		
		&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oRefreshNodes&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;ControlDefinition&lt;/SPAN&gt;
		&lt;SPAN&gt;oRefreshNodes&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;CommandManager&lt;/SPAN&gt;.&lt;SPAN&gt;ControlDefinitions&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;"MoldRefreshBrowserNodes"&lt;/SPAN&gt;)
		&lt;SPAN&gt;oRefreshNodes&lt;/SPAN&gt;.&lt;SPAN&gt;Execute&lt;/SPAN&gt;
		

	&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
&lt;SPAN&gt;Next&lt;/SPAN&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 12 Apr 2022 12:17:44 GMT</pubDate>
    <dc:creator>dalton98</dc:creator>
    <dc:date>2022-04-12T12:17:44Z</dc:date>
    <item>
      <title>iLogic for Save and Replace within an assembly by part name</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-for-save-and-replace-within-an-assembly-by-part-name/m-p/11098814#M136594</link>
      <description>&lt;P&gt;Hello All!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm wondering if someone can help me with some iLogic code. Basically I want to perform the "Save and Replace" fuction within an assembly, but via iLogic. I'd like the code to be able to find a part within an assembly by name, say "cube.ipt", and save a copy of cube.ipt using a filename I've already generated earlier in the code, say "my_custom_name.ipt", and then replace cube.ipt with my_custom_name.ipt in the assembly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this isn't possible, perhaps code that at least can save a copy of a given part? I can always replace a component but I need to generate the copy first.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice is greatly appreciated. Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2022 16:30:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-for-save-and-replace-within-an-assembly-by-part-name/m-p/11098814#M136594</guid>
      <dc:creator>nsheldonGGNEN</dc:creator>
      <dc:date>2022-04-11T16:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic for Save and Replace within an assembly by part name</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-for-save-and-replace-within-an-assembly-by-part-name/m-p/11100186#M136611</link>
      <description>&lt;P&gt;Do you want to replace all occurrences of this 'cube.ipt'?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have the full filename of the part you can, to save a copy of this part:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Dim doc as PartDocument = ThisApplication.Documents.Open(filename)
Call doc.SaveAs(newFilename, true)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then find the occurrence to be replaced in the assembly, either loop through the assemblies all (leaf) occurrences or access the occurrence by name (ItemByName) from the assemblies component definition. You can then replace it using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;ComponentOccurrence.Replace(filename, true) ' true/false depending on replace all&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 07:51:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-for-save-and-replace-within-an-assembly-by-part-name/m-p/11100186#M136611</guid>
      <dc:creator>basautomationservices</dc:creator>
      <dc:date>2022-04-12T07:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic for Save and Replace within an assembly by part name</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-for-save-and-replace-within-an-assembly-by-part-name/m-p/11100728#M136637</link>
      <description>&lt;P&gt;This should be what your looking for. First it goes through all reference docs and selects one with "cube.ipt" in its file path. Then it creates a copy of that naming it "my_custom_name". Then it makes a privite event to skip the dialog box. Then it runs the replace all cmd. Finally it refreshes the browser nodes.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oAss&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;AssemblyDocument&lt;/SPAN&gt;
&lt;SPAN&gt;oAss&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;ActiveDocument&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oDoc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Document&lt;/SPAN&gt;
&lt;SPAN&gt;For&lt;/SPAN&gt; &lt;SPAN&gt;Each&lt;/SPAN&gt; &lt;SPAN&gt;oDoc&lt;/SPAN&gt; &lt;SPAN&gt;In&lt;/SPAN&gt; &lt;SPAN&gt;oAss&lt;/SPAN&gt;.&lt;SPAN&gt;AllReferencedDocuments&lt;/SPAN&gt;
	&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;InStr&lt;/SPAN&gt;(&lt;SPAN&gt;oDoc&lt;/SPAN&gt;.&lt;SPAN&gt;FullDocumentName&lt;/SPAN&gt;, &lt;SPAN&gt;"cube.ipt"&lt;/SPAN&gt;) &amp;gt; 0
		&lt;SPAN&gt;template&lt;/SPAN&gt; = &lt;SPAN&gt;oDoc&lt;/SPAN&gt;.&lt;SPAN&gt;FullDocumentName&lt;/SPAN&gt;
		&lt;SPAN&gt;newlength&lt;/SPAN&gt; = &lt;SPAN&gt;InStrRev&lt;/SPAN&gt;(&lt;SPAN&gt;oDoc&lt;/SPAN&gt;.&lt;SPAN&gt;FullDocumentName&lt;/SPAN&gt;, &lt;SPAN&gt;"\"&lt;/SPAN&gt;)
		&lt;SPAN&gt;newfile&lt;/SPAN&gt; = &lt;SPAN&gt;Left&lt;/SPAN&gt;(&lt;SPAN&gt;template&lt;/SPAN&gt;, &lt;SPAN&gt;newlength&lt;/SPAN&gt;) &amp;amp; &lt;SPAN&gt;"my_custom_name.ipt"&lt;/SPAN&gt;
		&lt;SPAN&gt;IO&lt;/SPAN&gt;.&lt;SPAN&gt;File&lt;/SPAN&gt;.&lt;SPAN&gt;Copy&lt;/SPAN&gt;(&lt;SPAN&gt;template&lt;/SPAN&gt;, &lt;SPAN&gt;newfile&lt;/SPAN&gt;, &lt;SPAN&gt;True&lt;/SPAN&gt;)

		&lt;SPAN&gt;oDocName&lt;/SPAN&gt; = &lt;SPAN&gt;System&lt;/SPAN&gt;.&lt;SPAN&gt;IO&lt;/SPAN&gt;.&lt;SPAN&gt;Path&lt;/SPAN&gt;.&lt;SPAN&gt;GetFileNameWithoutExtension&lt;/SPAN&gt;(&lt;SPAN&gt;oDoc&lt;/SPAN&gt;.&lt;SPAN&gt;FullDocumentName&lt;/SPAN&gt;)
&lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;CommandManager&lt;/SPAN&gt;.&lt;SPAN&gt;PostPrivateEvent&lt;/SPAN&gt;(&lt;SPAN&gt;PrivateEventTypeEnum&lt;/SPAN&gt;.&lt;SPAN&gt;kFileNameEvent&lt;/SPAN&gt;, &lt;SPAN&gt;newfile&lt;/SPAN&gt;)
		&lt;SPAN&gt;compo&lt;/SPAN&gt; = &lt;SPAN&gt;Component&lt;/SPAN&gt;.&lt;SPAN&gt;InventorComponent&lt;/SPAN&gt;(&lt;SPAN&gt;oDocName&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;":1"&lt;/SPAN&gt;)
		&lt;SPAN&gt;oAss&lt;/SPAN&gt;.&lt;SPAN&gt;SelectSet&lt;/SPAN&gt;.&lt;SPAN&gt;Select&lt;/SPAN&gt;(&lt;SPAN&gt;compo&lt;/SPAN&gt;)
			
		
		&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oReplaceCmd&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;ControlDefinition&lt;/SPAN&gt;
		&lt;SPAN&gt;oReplaceCmd&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;CommandManager&lt;/SPAN&gt;.&lt;SPAN&gt;ControlDefinitions&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;"AssemblyReplaceAllCmd"&lt;/SPAN&gt;)
		&lt;SPAN&gt;oReplaceCmd&lt;/SPAN&gt;.&lt;SPAN&gt;Execute&lt;/SPAN&gt;
		
		&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oRefreshNodes&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;ControlDefinition&lt;/SPAN&gt;
		&lt;SPAN&gt;oRefreshNodes&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;CommandManager&lt;/SPAN&gt;.&lt;SPAN&gt;ControlDefinitions&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;"MoldRefreshBrowserNodes"&lt;/SPAN&gt;)
		&lt;SPAN&gt;oRefreshNodes&lt;/SPAN&gt;.&lt;SPAN&gt;Execute&lt;/SPAN&gt;
		

	&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
&lt;SPAN&gt;Next&lt;/SPAN&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Apr 2022 12:17:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-for-save-and-replace-within-an-assembly-by-part-name/m-p/11100728#M136637</guid>
      <dc:creator>dalton98</dc:creator>
      <dc:date>2022-04-12T12:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic for Save and Replace within an assembly by part name</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-for-save-and-replace-within-an-assembly-by-part-name/m-p/11101363#M136651</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply. Could you expand on how to call a specific instance by name and replace only that instance of a component? I attempted it uncessfully.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 16:23:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-for-save-and-replace-within-an-assembly-by-part-name/m-p/11101363#M136651</guid>
      <dc:creator>nsheldonGGNEN</dc:creator>
      <dc:date>2022-04-12T16:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic for Save and Replace within an assembly by part name</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-for-save-and-replace-within-an-assembly-by-part-name/m-p/11101367#M136652</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply. The code worked well for me! Only follow-up question would be is there a way to modify the code to only replace a specific instance of a component, rather than replacing all of them? This wasn't part of my original thought, but I could see this functionality being useful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for helping with this!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 16:24:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-for-save-and-replace-within-an-assembly-by-part-name/m-p/11101367#M136652</guid>
      <dc:creator>nsheldonGGNEN</dc:creator>
      <dc:date>2022-04-12T16:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic for Save and Replace within an assembly by part name</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-for-save-and-replace-within-an-assembly-by-part-name/m-p/11101442#M136654</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9370348"&gt;@nsheldonGGNEN&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Replace it with this "&lt;SPAN&gt;AssemblyReplaceCmd"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Someone made a helpful website that lists all the api commands:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://spiderinnet2.typepad.com/blog/2012/07/inventor-net-find-all-the-control-definitions-1.html" target="_blank"&gt;https://spiderinnet2.typepad.com/blog/2012/07/inventor-net-find-all-the-control-definitions-1.html&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 16:54:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-for-save-and-replace-within-an-assembly-by-part-name/m-p/11101442#M136654</guid>
      <dc:creator>dalton98</dc:creator>
      <dc:date>2022-04-12T16:54:11Z</dc:date>
    </item>
  </channel>
</rss>

