<?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: Changing all reference files for DWG file in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/changing-all-reference-files-for-dwg-file/m-p/11601145#M146108</link>
    <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9915864"&gt;@shrey9GP3F&lt;/a&gt;.&amp;nbsp; I am not fluent in C#, but it looks to me like the code posted here is missing a step.&amp;nbsp; In line 4, it looks like you are attempting to get 'ReferencedFileDescriptors' directly from a Document object (oDoc), but I believe you need to get the document's 'File', before you can then get that File.ReferencedFileDescriptors.&amp;nbsp; So, I believe you would need to replace this:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;foreach (Inventor.FileDescriptor oFileDesc in oDoc.ReferencedFileDescriptors)&lt;/LI-CODE&gt;
&lt;P&gt;...with this:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;foreach (Inventor.FileDescriptor oFileDesc in oDoc.File.ReferencedFileDescriptors)&lt;/LI-CODE&gt;
&lt;P&gt;However, if there are ModelStates involved, and you want to maintain each view's reference to the equivalent ModelState of the replacement model, then you may have to iterate each view, on each sheet, and replace its reference individually.&lt;/P&gt;
&lt;P&gt;DrawingView.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(sReplacementFileName)&lt;/P&gt;
&lt;P&gt;That way you can extract the originally specified ModelState name (or iPart/iAssembly Member name) before the replacement, then set it back after the replacement, to maintain it.&amp;nbsp; Each &lt;A href="https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=DrawingView" target="_blank" rel="noopener"&gt;DrawingView&lt;/A&gt; object has a property named &lt;A href="https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=DrawingView_ActiveMemberName" target="_blank" rel="noopener"&gt;ActiveMemberName&lt;/A&gt;, which records which iPart/iAssembly member it is set to, and a property named &lt;A href="https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=DrawingView_ActiveModelState" target="_blank" rel="noopener"&gt;ActiveModelState&lt;/A&gt;, which obviously records which ModelState it is set to.&amp;nbsp; But the ActiveModelState property is ReadOnly, so you would have to use the DrawingView.&lt;A href="https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=DrawingView_SetActiveModelState" target="_blank" rel="noopener"&gt;SetActiveModelState&lt;/A&gt; method to set the value back to the view after the replacement.&lt;/P&gt;</description>
    <pubDate>Tue, 06 Dec 2022 13:06:38 GMT</pubDate>
    <dc:creator>WCrihfield</dc:creator>
    <dc:date>2022-12-06T13:06:38Z</dc:date>
    <item>
      <title>Changing all reference files for DWG file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/changing-all-reference-files-for-dwg-file/m-p/11599231#M146079</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to replace all the reference files for an Inventor DWG file (new files already exist in the target folder). But &lt;EM&gt;ReferencedFileDescriptor &lt;/EM&gt;does&amp;nbsp;not replace the suppressed files. How do I replace all the file references without modifying the model state?&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;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public static void ChangeRef(Inventor.Document oDoc)
        {

            foreach (Inventor.FileDescriptor oFileDesc in oDoc.File.ReferencedFileDescriptors)
            {
                string oSubFileName = System.IO.Path.GetFileNameWithoutExtension(oFileDesc.FullFileName);
                string oSubFileExt = System.IO.Path.GetExtension(oFileDesc.FullFileName);
                string oSubNewFileName =  @"C:\Users\Public\Desktop\NewFolder\" + oSubFileName + "_NEW" + oSubFileExt;


                oFileDesc.ReplaceReference(oSubNewFileName);
            }
        }&lt;/LI-CODE&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;&amp;nbsp;&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;</description>
      <pubDate>Tue, 06 Dec 2022 16:31:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/changing-all-reference-files-for-dwg-file/m-p/11599231#M146079</guid>
      <dc:creator>shrey9GP3F</dc:creator>
      <dc:date>2022-12-06T16:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: Changing all reference files for DWG file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/changing-all-reference-files-for-dwg-file/m-p/11601145#M146108</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9915864"&gt;@shrey9GP3F&lt;/a&gt;.&amp;nbsp; I am not fluent in C#, but it looks to me like the code posted here is missing a step.&amp;nbsp; In line 4, it looks like you are attempting to get 'ReferencedFileDescriptors' directly from a Document object (oDoc), but I believe you need to get the document's 'File', before you can then get that File.ReferencedFileDescriptors.&amp;nbsp; So, I believe you would need to replace this:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;foreach (Inventor.FileDescriptor oFileDesc in oDoc.ReferencedFileDescriptors)&lt;/LI-CODE&gt;
&lt;P&gt;...with this:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;foreach (Inventor.FileDescriptor oFileDesc in oDoc.File.ReferencedFileDescriptors)&lt;/LI-CODE&gt;
&lt;P&gt;However, if there are ModelStates involved, and you want to maintain each view's reference to the equivalent ModelState of the replacement model, then you may have to iterate each view, on each sheet, and replace its reference individually.&lt;/P&gt;
&lt;P&gt;DrawingView.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(sReplacementFileName)&lt;/P&gt;
&lt;P&gt;That way you can extract the originally specified ModelState name (or iPart/iAssembly Member name) before the replacement, then set it back after the replacement, to maintain it.&amp;nbsp; Each &lt;A href="https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=DrawingView" target="_blank" rel="noopener"&gt;DrawingView&lt;/A&gt; object has a property named &lt;A href="https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=DrawingView_ActiveMemberName" target="_blank" rel="noopener"&gt;ActiveMemberName&lt;/A&gt;, which records which iPart/iAssembly member it is set to, and a property named &lt;A href="https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=DrawingView_ActiveModelState" target="_blank" rel="noopener"&gt;ActiveModelState&lt;/A&gt;, which obviously records which ModelState it is set to.&amp;nbsp; But the ActiveModelState property is ReadOnly, so you would have to use the DrawingView.&lt;A href="https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=DrawingView_SetActiveModelState" target="_blank" rel="noopener"&gt;SetActiveModelState&lt;/A&gt; method to set the value back to the view after the replacement.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2022 13:06:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/changing-all-reference-files-for-dwg-file/m-p/11601145#M146108</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2022-12-06T13:06:38Z</dc:date>
    </item>
  </channel>
</rss>

