<?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: How to Make the Opened Assembly the Current Document When Running an External iLogic Rule in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-make-the-opened-assembly-the-current-document-when/m-p/13644335#M92</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/15812381"&gt;@leebrg&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think we can do this but we’d need to get the document as an ilogic document object in the 2nd rule.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I’m about to hop on a flight, but I’ll ask to get this moved to ilogic forum where one of our ilogic focused community members can have a look at you question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hope that help,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;curtis&lt;/P&gt;</description>
    <pubDate>Thu, 22 May 2025 10:58:30 GMT</pubDate>
    <dc:creator>Curtis_W</dc:creator>
    <dc:date>2025-05-22T10:58:30Z</dc:date>
    <item>
      <title>How to Make the Opened Assembly the Current Document When Running an External iLogic Rule</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-make-the-opened-assembly-the-current-document-when/m-p/13644098#M91</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;To make the question easy to understand, let's assume the following file names:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Assembly1.iam&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Assembly2.iam&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;EXRule1.iLogicVb&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;EXRule2.iLogicVb&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;Assembly1.iam is currently open.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;While this document is active, I run the external rule EXRule1.iLogicVb.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Inside EXRule1, it opens Assembly2.iam and runs another external rule called EXRule2.&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Here’s the simplified code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Dim&lt;/SPAN&gt; oDocName &lt;SPAN class=""&gt;As&lt;/SPAN&gt; &lt;SPAN class=""&gt;String&lt;/SPAN&gt;
oDocName = &lt;SPAN class=""&gt;"C:\Temp\Assembly2.iam"&lt;/SPAN&gt;
&lt;SPAN class=""&gt;Dim&lt;/SPAN&gt; openDocument &lt;SPAN class=""&gt;As&lt;/SPAN&gt; AssemblyDocument = ThisApplication.Documents.Open(oDocName, &lt;SPAN class=""&gt;True&lt;/SPAN&gt;)
openDocument.Activate()
iLogicVb.RunExternalRule(&lt;SPAN class=""&gt;"EXRule2"&lt;/SPAN&gt;)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;HR /&gt;&lt;P&gt;The Problem:&lt;/P&gt;&lt;P&gt;In EXRule2.iLogicVb, when I try to access parameters or properties using ThisDoc,&lt;BR /&gt;&lt;STRONG&gt;it still points to Assembly1.iam&lt;/STRONG&gt;, not the newly opened Assembly2.iam.&lt;/P&gt;&lt;P&gt;However, all logic inside EXRule2 is written &lt;STRONG&gt;assuming&lt;/STRONG&gt; that the &lt;EM&gt;current document is Assembly2.iam&lt;/EM&gt;,&lt;BR /&gt;so most parameter calls are like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;Parameter(&lt;SPAN class=""&gt;"MyParam"&lt;/SPAN&gt;)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;If I use ThisApplication.ActiveDocument instead, then I'd need to rewrite all parameter calls like:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Dim&lt;/SPAN&gt; oDoc &lt;SPAN class=""&gt;As&lt;/SPAN&gt; AssemblyDocument = ThisApplication.ActiveDocument
&lt;SPAN class=""&gt;Dim&lt;/SPAN&gt; myParam &lt;SPAN class=""&gt;As&lt;/SPAN&gt; &lt;SPAN class=""&gt;String&lt;/SPAN&gt; = oDoc.ComponentDefinition.Parameters(&lt;SPAN class=""&gt;"MyParam"&lt;/SPAN&gt;).Value&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;But the problem is, there are &lt;STRONG&gt;hundreds of parameters&lt;/STRONG&gt; used in EXRule2, and rewriting all of them is not realistic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way to make the newly opened Assembly2.iam be recognized as &lt;EM&gt;ThisDoc&lt;/EM&gt; in EXRule2?&lt;BR /&gt;Or any workaround that allows me to keep using short form like Parameter("MyParam") inside the rule&lt;BR /&gt;as if Assembly2.iam is the current document?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas or best practices would be greatly appreciated.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 22 May 2025 08:44:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-make-the-opened-assembly-the-current-document-when/m-p/13644098#M91</guid>
      <dc:creator>leebrg</dc:creator>
      <dc:date>2025-05-22T08:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to Make the Opened Assembly the Current Document When Running an External iLogic Rule</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-make-the-opened-assembly-the-current-document-when/m-p/13644335#M92</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/15812381"&gt;@leebrg&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think we can do this but we’d need to get the document as an ilogic document object in the 2nd rule.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I’m about to hop on a flight, but I’ll ask to get this moved to ilogic forum where one of our ilogic focused community members can have a look at you question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hope that help,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;curtis&lt;/P&gt;</description>
      <pubDate>Thu, 22 May 2025 10:58:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-make-the-opened-assembly-the-current-document-when/m-p/13644335#M92</guid>
      <dc:creator>Curtis_W</dc:creator>
      <dc:date>2025-05-22T10:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to Make the Opened Assembly the Current Document When Running an External iLogic Rule</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-make-the-opened-assembly-the-current-document-when/m-p/13644890#M93</link>
      <description>&lt;P&gt;Instead of using this:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;iLogicVb.RunExternalRule("EXRule2")&lt;/LI-CODE&gt;
&lt;P&gt;...another option would be to use this:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim oArgs As Inventor.NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
oArgs.Value("Document") = openDocument
iLogicVb.Automation.RunExternalRuleWithArguments(openDocument, "EXRule2", oArgs)&lt;/LI-CODE&gt;
&lt;P&gt;Now, when 'EXRule2' runs, its 'ThisDoc.Document' should be pointing to that 'openDocument' that you specified as the first 'input' to that method.&lt;/P&gt;
&lt;P&gt;And, if you wanted to, you could use the 'arguments' to 'receive' the Document object that was 'sent' to that second rule, like the following...as an optional.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim oDoc As Inventor.Document = Nothing
If RuleArguments.Exists("Document") Then
	oDoc = RuleArguments.Value("Document")
Else
	oDoc = ThisDoc.Document
End If
If oDoc Is Nothing Then Return 'exit if no document&lt;/LI-CODE&gt;
&lt;P&gt;The '&lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=c6f2c020-8318-5536-3e1f-c57a5125071b" target="_blank" rel="noopener"&gt;RuleArguments&lt;/A&gt;' is unique to the iLogic add-in, and is its way to 'share' data between rules.&amp;nbsp; Another tool for that purpose that is also unique to the iLogic add-in is the &lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=4ccb78b0-c35c-4d38-943a-854117da6ced" target="_blank" rel="noopener"&gt;Rule Object&lt;/A&gt; named '&lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=9da80dee-a3ae-2f47-324b-4ef496b40e5b" target="_blank" rel="noopener"&gt;SharedVariable&lt;/A&gt;'.&amp;nbsp; The SharedVariable system is essentially a temporary 2-factor (each item/entry has 2 parts) collection of objects that the iLogic add-in creates for us.&amp;nbsp; The data in it does not survive after Inventor quits, because it is just being held in Inventor's session memory.&lt;/P&gt;</description>
      <pubDate>Thu, 22 May 2025 15:19:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-make-the-opened-assembly-the-current-document-when/m-p/13644890#M93</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2025-05-22T15:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to Make the Opened Assembly the Current Document When Running an External iLogic Rule</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-make-the-opened-assembly-the-current-document-when/m-p/13652524#M94</link>
      <description>&lt;P&gt;Thank you. I tried the code you provided, and it solved the problem. I'm really grateful. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 May 2025 00:01:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-make-the-opened-assembly-the-current-document-when/m-p/13652524#M94</guid>
      <dc:creator>leebrg</dc:creator>
      <dc:date>2025-05-28T00:01:02Z</dc:date>
    </item>
  </channel>
</rss>

