<?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: Need to run an external rule for all parts of an assembly in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/7935317#M90080</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your current writing of the rule doesn't know the CONTEXT that the iLogic rule is supposed to be run in, so it's currently the equivalent of saying "run the rule where it is, 100 times".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To fix that, you need to supply the iLogic Rule call with some CONTEXT (ie; the DOCUMENT the rule is supposed to effect).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Dim aDoc As AssemblyDocument
aDoc = ThisApplication.ActiveDocument

Dim iDoc As Document

For Each iDoc In aDoc.AllReferencedDocuments
    iLogicVb.RunExternalRule(iDoc, "Test")&lt;BR /&gt;Next&lt;/PRE&gt;</description>
    <pubDate>Mon, 16 Apr 2018 14:06:38 GMT</pubDate>
    <dc:creator>MechMachineMan</dc:creator>
    <dc:date>2018-04-16T14:06:38Z</dc:date>
    <item>
      <title>Need to run an external rule for all parts of an assembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/7920254#M90078</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I am trying to add some custom iproperties to all the sheet metal parts in an assembly using an external rule.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the assembly rule:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;aDoc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;AssemblyDocument&lt;/SPAN&gt;
&lt;SPAN&gt;aDoc&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;iDoc&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;iDoc&lt;/SPAN&gt; &lt;SPAN&gt;In&lt;/SPAN&gt; &lt;SPAN&gt;aDoc&lt;/SPAN&gt;.&lt;SPAN&gt;AllReferencedDocuments&lt;/SPAN&gt;
&lt;SPAN&gt;iLogicVb&lt;/SPAN&gt;.&lt;SPAN&gt;RunExternalRule&lt;/SPAN&gt;(&lt;SPAN&gt;"Test"&lt;/SPAN&gt;)
 &lt;SPAN&gt;Next&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;And here's the external rule:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;'Assigning Sheet metal Parameters&lt;/SPAN&gt;
&lt;SPAN&gt;iProperties&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt;(&lt;SPAN&gt;"Custom"&lt;/SPAN&gt;, &lt;SPAN&gt;"LENGTH"&lt;/SPAN&gt;) = &lt;SPAN&gt;Round&lt;/SPAN&gt;(&lt;SPAN&gt;SheetMetal&lt;/SPAN&gt;.&lt;SPAN&gt;FlatExtentsLength&lt;/SPAN&gt;)  &lt;SPAN&gt;'LENGTH OF THE PART FOR CUTTIN LIST&lt;/SPAN&gt;
&lt;SPAN&gt;iProperties&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt;(&lt;SPAN&gt;"Custom"&lt;/SPAN&gt;, &lt;SPAN&gt;"WIDTH"&lt;/SPAN&gt;) = &lt;SPAN&gt;Round&lt;/SPAN&gt;(&lt;SPAN&gt;SheetMetal&lt;/SPAN&gt;.&lt;SPAN&gt;FlatExtentsWidth&lt;/SPAN&gt;)   &lt;SPAN&gt;'WIDTH OF THE PART FOR CUTTING LIST&lt;/SPAN&gt;
&lt;SPAN&gt;iProperties&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt;(&lt;SPAN&gt;"Custom"&lt;/SPAN&gt;, &lt;SPAN&gt;"THICKNESS"&lt;/SPAN&gt;) = &lt;SPAN&gt;Thickness&lt;/SPAN&gt; &lt;SPAN&gt;'MODEL PROPERTY EQUALS TO CUSTOM IPROPERTY&lt;/SPAN&gt;

 
&lt;SPAN&gt;iProperties&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt;(&lt;SPAN&gt;"Custom"&lt;/SPAN&gt;, &lt;SPAN&gt;"AREA"&lt;/SPAN&gt;) = &lt;SPAN&gt;Round&lt;/SPAN&gt;((&lt;SPAN&gt;SheetMetal&lt;/SPAN&gt;.&lt;SPAN&gt;FlatExtentsArea&lt;/SPAN&gt; / 92903.04),2) &lt;SPAN&gt;'AREA OF THE PART FOR CUTTING LIST IN SFT&lt;/SPAN&gt;
 
 
&lt;SPAN&gt;iProperties&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt;(&lt;SPAN&gt;"Custom"&lt;/SPAN&gt;, &lt;SPAN&gt;"MATERIAL"&lt;/SPAN&gt;) = &lt;SPAN&gt;iProperties&lt;/SPAN&gt;.&lt;SPAN&gt;Material&lt;/SPAN&gt;
 
&lt;SPAN&gt;iLogicVb&lt;/SPAN&gt;.&lt;SPAN&gt;UpdateWhenDone&lt;/SPAN&gt; = &lt;SPAN&gt;True&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;After running the assembly rule, there are no changes at all to any parts of the assembly. Only custom iproperties are added to assembly as 0.0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;P.S I am a newbie in iLogic and wrote the codes after learning from forums. Please feel free to point out any silly mistakes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;kp&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 06:32:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/7920254#M90078</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-04-10T06:32:38Z</dc:date>
    </item>
    <item>
      <title>Re: Need to run an external rule for all parts of an assembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/7935297#M90079</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not sure iLogic is the right way here.&lt;/P&gt;
&lt;P&gt;You can do it with classic VBA script.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is short example how to open documents with VBA.&lt;/P&gt;
&lt;P&gt;Public Declare PtrSafe Function GetTickCount Lib "kernel32" () As Long&lt;BR /&gt;Sub Main()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mlngStart = GetTickCount&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim oDoc As Document&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; For i = 0 To 4&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ThisApplication.Documents.Open ("D:\tu\" &amp;amp; i &amp;amp; ".ipt")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next i&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EndTimer = (GetTickCount - mlngStart)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "open time&amp;nbsp; " &amp;amp; EndTimer&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; For Each oDoc In ThisApplication.Documents&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oDoc.Close (True)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next oDoc&lt;BR /&gt;End Sub&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;D:\tu\ folder must contains files &lt;/P&gt;
&lt;P&gt;0.ipt 1.ipt&amp;nbsp; ..... 5.ipt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Martin&lt;/P&gt;</description>
      <pubDate>Mon, 16 Apr 2018 14:00:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/7935297#M90079</guid>
      <dc:creator>martin.jacko</dc:creator>
      <dc:date>2018-04-16T14:00:55Z</dc:date>
    </item>
    <item>
      <title>Re: Need to run an external rule for all parts of an assembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/7935317#M90080</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your current writing of the rule doesn't know the CONTEXT that the iLogic rule is supposed to be run in, so it's currently the equivalent of saying "run the rule where it is, 100 times".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To fix that, you need to supply the iLogic Rule call with some CONTEXT (ie; the DOCUMENT the rule is supposed to effect).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Dim aDoc As AssemblyDocument
aDoc = ThisApplication.ActiveDocument

Dim iDoc As Document

For Each iDoc In aDoc.AllReferencedDocuments
    iLogicVb.RunExternalRule(iDoc, "Test")&lt;BR /&gt;Next&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Apr 2018 14:06:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/7935317#M90080</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2018-04-16T14:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: Need to run an external rule for all parts of an assembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/7936881#M90081</link>
      <description>&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;That helped &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just one more question&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What's the difference in running the external rule like:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;iLogicVb.RunExternalRule(iDoc, "Test")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And using automation like:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;auto=iLogicVb.Automation&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;auto.RunExternalRule(iDoc, "Test")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Apr 2018 03:58:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/7936881#M90081</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-04-17T03:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: Need to run an external rule for all parts of an assembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/8342597#M90082</link>
      <description>&lt;P&gt;This rule is exactly what i'm looking for also, however when&amp;nbsp;i try rule this rule i get this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Unable to cast COM object of type 'System.__ComObject' to class type 'System.String'. 
Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Oct 2018 08:52:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/8342597#M90082</guid>
      <dc:creator>matthew.johnson200</dc:creator>
      <dc:date>2018-10-18T08:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Need to run an external rule for all parts of an assembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/8348213#M90083</link>
      <description>&lt;P&gt;Hi Matthew&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's been a while since I have posted this query. I am afraid I won't be able to help you with your specific error. But, below is the code that worked for me:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ASSEMBLY RULE&lt;/P&gt;&lt;P&gt;Dim aDoc As AssemblyDocument&lt;/P&gt;&lt;P&gt;aDoc = ThisApplication.ActiveDocument&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dim iDoc As Document&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For Each iDoc In aDoc.AllReferencedDocuments&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If iDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then&lt;/P&gt;&lt;P&gt;auto = iLogicVb.Automation&lt;/P&gt;&lt;P&gt;auto.RunExternalRule(iDoc, ”Sheet Metal Parameters”)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;iDoc.Close()&lt;/P&gt;&lt;P&gt;End If&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next&lt;/P&gt;&lt;P&gt;iLogicVb.UpdateWhenDone = True&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This rule basically identifies all the sheet metal parts in the assembly, runs an external rule named "Sheet Metal Parameters" and then closes that part document.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Kp&lt;/P&gt;</description>
      <pubDate>Sun, 21 Oct 2018 04:45:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/8348213#M90083</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-10-21T04:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Need to run an external rule for all parts of an assembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/8365833#M90084</link>
      <description>&lt;P&gt;This worked great.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2018 14:23:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/8365833#M90084</guid>
      <dc:creator>matthew.johnson200</dc:creator>
      <dc:date>2018-10-29T14:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: Need to run an external rule for all parts of an assembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/8866306#M90085</link>
      <description>&lt;P&gt;Thanks a lot. Found a many solutions in the forum. Was about to post in the forum for help, but finally, I found your code helping me. Thanks a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;aDoc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;AssemblyDocument&lt;/SPAN&gt;
&lt;SPAN&gt;aDoc&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;iDoc&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;iDoc&lt;/SPAN&gt; &lt;SPAN&gt;In&lt;/SPAN&gt; &lt;SPAN&gt;aDoc&lt;/SPAN&gt;.&lt;SPAN&gt;AllReferencedDocuments&lt;/SPAN&gt;
&lt;SPAN&gt;auto&lt;/SPAN&gt; = &lt;SPAN&gt;iLogicVb&lt;/SPAN&gt;.&lt;SPAN&gt;Automation&lt;/SPAN&gt;
&lt;SPAN&gt;auto&lt;/SPAN&gt;.&lt;SPAN&gt;RunExternalRule&lt;/SPAN&gt;(&lt;SPAN&gt;iDoc&lt;/SPAN&gt;, &lt;SPAN&gt;"D:\Vault Workspace\Projects\ExternalRules\Rules\Test"&lt;/SPAN&gt;)
&lt;SPAN&gt;iDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Close&lt;/SPAN&gt;()
&lt;SPAN&gt;Next&lt;/SPAN&gt;
&lt;SPAN&gt;iLogicVb&lt;/SPAN&gt;.&lt;SPAN&gt;UpdateWhenDone&lt;/SPAN&gt; = &lt;SPAN&gt;True&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;I need to tailor the rule for my needs, will revert to you for help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2019 08:23:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/8866306#M90085</guid>
      <dc:creator>RoyWickrama_RWEI</dc:creator>
      <dc:date>2019-06-22T08:23:24Z</dc:date>
    </item>
    <item>
      <title>Re: Need to run an external rule for all parts of an assembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/10185308#M90086</link>
      <description>&lt;P&gt;Hallo, sorry for necroing&lt;/P&gt;&lt;P&gt;i'm triying to use this feature too.&lt;/P&gt;&lt;P&gt;Our company runs inventor 2014 (this may be the problem but i'm not sure)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so in the assembly i would run this rule&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Dim aDoc As AssemblyDocument
aDoc = ThisApplication.ActiveDocument
Dim iDoc As Document
For Each iDoc In aDoc.AllReferencedDocuments
'lamiere
If iDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
auto = iLogicVb.Automation
auto.RunExternalRule(iDoc, "aggiungi regole materiali")
iDoc.Close()
End If
'parti
If iDoc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then
auto = iLogicVb.Automation
auto.RunExternalRule(iDoc, "aggiungi regole materiali")
iDoc.Close()
End If
'prossimo file
Next
iLogicVb.UpdateWhenDone = True&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which should run the external rule "aggiungi regole materiali" on each sheetmetal and part in the assembly&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is the rule i run&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt; 
' Questa regola aggiunge una regola locale per la gestione dei materiali

Dim RuleName As String = 	"Materiale"
Dim RuleText As String = 	"' Hello - This is an automatically created iLogic rule" &amp;amp; vbCrLf &amp;amp; _
							"Dim oPartDoc As Inventor.PartDocument = ThisDoc.Document" &amp;amp; vbCrLf &amp;amp; _
							"Dim mat_norm As String = oPartDoc.ActiveMaterial.Item(""physmat_Comments"").Value" &amp;amp; vbCrLf &amp;amp; _
							"Dim stringa1 as String = """"" &amp;amp; vbCrLf &amp;amp; _
							"Dim stringa2 as String = """"" &amp;amp; vbCrLf &amp;amp; _
							"Dim stringa3 as String = """"" &amp;amp; vbCrLf &amp;amp; _
							"If mat_resi=""-"" Then" &amp;amp; vbCrLf &amp;amp; _ 
							"stringa1="""" " &amp;amp; vbCrLf &amp;amp; _ 
							"Else" &amp;amp; vbCrLf &amp;amp; _ 
"stringa1=mat_resi" &amp;amp; vbCrLf &amp;amp; _ 
"End If" &amp;amp; vbCrLf &amp;amp; _
"If mat_forn=""-"" Then" &amp;amp; vbCrLf &amp;amp; _ 
"stringa2="""" " &amp;amp; vbCrLf &amp;amp; _ 
"Else" &amp;amp; vbCrLf &amp;amp; _ 
"stringa2="" ""&amp;amp;mat_forn" &amp;amp; vbCrLf &amp;amp; _
"End If" &amp;amp; vbCrLf &amp;amp; _
"If mat_norm=""-"" Then" &amp;amp; vbCrLf &amp;amp; _
"stringa3="""" " &amp;amp; vbCrLf &amp;amp; _
"Else" &amp;amp; vbCrLf &amp;amp; _
"stringa3="" ""&amp;amp;mat_norm" &amp;amp; vbCrLf &amp;amp; _
"End If" &amp;amp; vbCrLf &amp;amp; _
"iProperties.Value(""Custom"", ""MAT_EST"")=ThisDoc.Document.ComponentDefinition.Material.Name &amp;amp; stringa1 &amp;amp; stringa2 &amp;amp; stringa3"&amp;amp; vbCrLf &amp;amp; _
"'non so perché ma la regola vuole questa riga commentata in fondo"

Dim oDoc As Document = ThisApplication.ActiveEditDocument                         
Dim iLogicAddIn As ApplicationAddIn = ThisApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
Dim iLogic As Object = iLogicAddIn.Automation
iLogic.DeleteRule(oDoc, RuleName)
iLogic.AddRule(oDoc, RuleName, RuleText)

SharedVariable("myRuleName") = "Materiale"                  		'Nome della regola.
SharedVariable("myTrigger") = "Any Model Parameter Change"    		'Tipo di trigger, deve essere esattamente quello che viene visualizzato nella finestra gestione trigger
SharedVariable("myAction") = "Add"                      			'il codice può essere usato per "Add" o "Remove" una regola da un trigger	
iLogicVb.RunExternalRule("EventTriggerSet")
SharedVariable.RemoveAll()
SharedVariable("myRuleName") = "Materiale"                  		'Nome della regola.
SharedVariable("myTrigger") = "Material Change"    					'Tipo di trigger, deve essere esattamente quello che viene visualizzato nella finestra gestione trigger
SharedVariable("myAction") = "Add"                      			'il codice può essere usato per "Add" o "Remove" una regola da un trigger	
iLogicVb.RunExternalRule("EventTriggerSet")
SharedVariable.RemoveAll()

oMyParameter=ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
oParameter=oMyParameter.AddByValue("mat_resi", "-", UnitsTypeEnum.kTextUnits)
oParameter=oMyParameter.AddByValue("mat_forn", "-", UnitsTypeEnum.kTextUnits)
MultiValue.SetList("mat_resi", "-", "J0", "J2", "JR", "K0", "K2", "KR", "L", "L0", "L2", "LR")
Parameter("mat_resi") = "-"
MultiValue.SetList("mat_forn", "-", "+M", "+N (TD)", "+Q", "+QT (TF)", "+T")
Parameter("mat_forn") = "-"

iLogicVb.RunRule("Materiale")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if i run this one on a single part or sheetmetal it works: it creates a rule, applies it to triggers and adds 2 parameters that the new rule uses, then it runs the new rule&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if i use the assembly rule this is the error i get:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;System.InvalidCastException: Impossibile eseguire il cast di oggetti COM di tipo 'System.__ComObject' in tipi di interfaccia 'Inventor.PartDocument'. L'operazione non è stata completata perché la chiamata QueryInterface sul componente COM per l'interfaccia con IID '{29F0D463-C114-11D2-B77F-0060B0F159EF}' non è riuscita a causa del seguente errore: Interfaccia non supportata. (Eccezione da HRESULT: 0x80004002 (E_NOINTERFACE)).
   in LmiRuleScript.Main()
   in Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   in iLogic.RuleEvalContainer.ExecRuleEval(String execRule)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and then for each part of the assembly it says it could not find the parameter "mat_resi" which the rule should have added.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am grateful for all the help i can get. I'm still a newbie to ilogic and i don't understand everything i do (many things come from this forums and work, i don't question them)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Mar 2021 07:30:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/10185308#M90086</guid>
      <dc:creator>adrian.kostilekBVRH9</dc:creator>
      <dc:date>2021-03-25T07:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a condition that if a part already has a rule, the rule will not run with that part</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/12965761#M90087</link>
      <description>&lt;PRE&gt;&lt;SPAN class=""&gt;How to add a condition that if a part already has a rule, the rule will not run with that part&lt;/SPAN&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 18 Aug 2024 14:04:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/12965761#M90087</guid>
      <dc:creator>halooween123</dc:creator>
      <dc:date>2024-08-18T14:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a condition that if a part already has a rule, the rule will not run with that part</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/12970588#M90088</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/14975496"&gt;@halooween123&lt;/a&gt;.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Do you only want the external rule to run on parts (not on sub assemblies)?&lt;/LI&gt;
&lt;LI&gt;Can you explain "already has a rule" in more detail?
&lt;UL&gt;
&lt;LI&gt;A specifically named rule, or just any rule?&lt;/LI&gt;
&lt;LI&gt;If specifically named, then what is the name of the rule that it might find in the part?
&lt;UL&gt;
&lt;LI&gt;assume spelling and capitalization are important.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;Can you explain "the rule will not run with that part" in more detail?
&lt;UL&gt;
&lt;LI&gt;By "the rule", do you mean the external rule, or the internal rule found within that part?&lt;/LI&gt;
&lt;LI&gt;So, do you mean...if the part contains (a specific / or any) internal iLogic rule, then do not run this external iLogic rule on that part?&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Here is an iLogic rule example that will only process parts (not sub assemblies) being referenced by the current document, and can be used either way (any internal rules in part or specific rule in part).&amp;nbsp; Just change the rule names in Lines 3 &amp;amp; 4, and choose which Line (Line 8 or Line 10) should be 'commented out' and which line the rule should use.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim oDoc As Document = ThisDoc.Document
Dim oAuto As IiLogicAutomation = iLogicVb.Automation
Dim sExtRuleName As String = "My External Rule Name"
Dim sIntRuleName As String = "Name of Internal Rule In Part"
For Each oRefDoc As Document In oDoc.AllReferencedDocuments
	If TypeOf oRefDoc Is PartDocument Then
		'next line checks for 'any' internal iLogic rules - if any found, skip this part
'		If oAuto.Rules(oRefDoc) IsNot Nothing Then Continue For
		'next line checks for 'specific' internal iLogic rule - if found, skip this part
		If oAuto.GetRule(oRefDoc, sIntRuleName) IsNot Nothing Then Continue For
		oAuto.RunExternalRule(oRefDoc, sExtRuleName)
	End If
Next oRefDoc
oDoc.Update2(True)&lt;/LI-CODE&gt;
&lt;P&gt;PS.&amp;nbsp; If the external rule is not using the iLogic code phrase 'ThisDoc.Document' to obtain a reference to the document it should be focused on, and is using 'ThisApplication.ActiveDocument' instead, then providing the referenced document to the RunExternalRule method in Line 11 will not work properly for you, and you may need to change that phrase in your external rule.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this solved your problem, or answered your question, please click &lt;SPAN&gt;&lt;STRONG&gt; ACCEPT SOLUTION &lt;/STRONG&gt;&lt;/SPAN&gt;.&lt;BR /&gt;Or, if this helped you, please click (LIKE or KUDOS) &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2024 18:49:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/need-to-run-an-external-rule-for-all-parts-of-an-assembly/m-p/12970588#M90088</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2024-08-20T18:49:18Z</dc:date>
    </item>
  </channel>
</rss>

