<?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: Run macro in assembly occurrences in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609556#M61459</link>
    <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5406798"&gt;@_dscholtes_&lt;/a&gt; , as I said before, that code is from &lt;A href="https://hoppend.nl/inventor.htm" target="_blank" rel="noopener"&gt;hoppend.nl&lt;/A&gt; , I just modified the minimun. I see the problem, but right now it's not running the macro, the main task of these rules.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you look at my original post, you can see that I have used both, occurrences and documents in assembly, but the macro is not running on part level, only on assembly level.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will try to modify the macro as suggested by &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1734991"&gt;@marcin_otręba&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jun 2020 09:02:57 GMT</pubDate>
    <dc:creator>isidro.nunez</dc:creator>
    <dc:date>2020-06-30T09:02:57Z</dc:date>
    <item>
      <title>Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9607840#M61446</link>
      <description>&lt;P&gt;Hello again,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to create a rule which can be run from an assembly and update/create all the ilogics of each part in that assembly. I have a macro that works fine when I open a part one by one. This macro creates or updates all the ilogic rules, parameters and iproperties needed, no problem here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem comes when I try to run a simple rule from an assembly and iterate through all the part or occurrecces.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This code is from hoppend.nl, I simply modified it a bit.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Sub Main()
'Define the Assembly Document
Dim oDoc As AssemblyDocument
Dim RuleName As String = "Check"

' check if active document is an assembly
Try
	oDoc = ThisApplication.ActiveDocument
Catch
	MessageBox.Show("Please run on assembly", "Run Rule")
End Try

Dim oOcc As ComponentOccurrence

GoThrough:
For Each oOcc In oDoc.ComponentDefinition.Occurrences
		'Get Document from Occurrence
		Dim oOccDoc As Document
		oOccDoc = oOcc.Definition.Document

		'Check if document is a part
		If oOccDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then

			oOccDoc = oOcc.Definition.Document
			Try
			InventorVb.RunMacro("Default", "Importar_ilogic", "Importar_ilogic")
			iLogicVb.RunRule(oOccDoc.DisplayName, RuleName)
			'MessageBox.Show("Rule run in: " &amp;amp; oOccDoc.DisplayName, "Message for debugging purposes")
			Catch
				'MessageBox.Show("Rule not present in: " &amp;amp; oOccDoc.DisplayName, "Message for debugging purposes")
			End Try
		'if the document is an assembly we need to run the same code in each occurrence of that assembly (we uses a goto function)
		Else If oOccDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject	Then
			oDoc = oOccDoc
			GoTo GoThrough
		End If
Next

End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I also tried this code (just ignore the vendor check):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Dim openDoc As Document
openDoc = ThisDoc.Document

Dim docFile As Document

If openDoc.DocumentType = 12291 Then
On Error Resume Next

	For Each docFile In openDoc.AllReferencedDocuments
		
		If docFile.DocumentType = 12290 Then
			
			prov_data = iProperties.Value(docFile.DisplayName, "Project", "Vendor")
			
			If prov_data = "Prov1" Then
				
				InventorVb.RunMacro("Default", "Importar_ilogic", "Importar_ilogic")
				'iLogicVb.RunRule("PartA:1", "ruleName")
			End If
		End If 
	Next
End If &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea how I can solve this?&lt;/P&gt;&lt;P&gt;Thank you a lot in advance.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 14:03:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9607840#M61446</guid>
      <dc:creator>isidro.nunez</dc:creator>
      <dc:date>2020-06-29T14:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9608213#M61447</link>
      <description>&lt;P&gt;Have you tried running an empty rule with just your RunMacro line in it, to make sure you're accessing the macro correctly?&lt;/P&gt;&lt;LI-CODE lang="general"&gt;InventorVb.RunMacro("Default", "Importar_ilogic", "Importar_ilogic")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 16:55:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9608213#M61447</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2020-06-29T16:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609150#M61448</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9046101"&gt;@isidro.nunez&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can try with excel vba, them will quickly and easier.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Sub UpdateParameterPartInAssy()
    Dim oWkbk As Workbook
    Set oWkbk = ThisWorkbook
    Dim oSheet As Worksheet
    Set oSheet = oWkbk.ActiveSheet
    Dim oInv As Inventor.Application
    Set oInv = GetObject(, "Inventor.Application")
    'Define sheet name where information resides
    Dim sSheetName As String
    sSheetName = "Sheet1"
    Dim oAssy As AssemblyDocument
    Set oAssy = oInv.ActiveDocument
    Dim sParamRange As String
        sParamRange = "A2:A20"
    Dim oDoc As Document
    For Each oDoc In oAssy.AllReferencedDocuments
        If oDoc.DocumentType = kPartDocumentObject Then
            Dim oPartDoc As PartDocument
            Set oPartDoc = oDoc
            Dim oUserParams As UserParameters
            Set oUserParams = oPartDoc.ComponentDefinition.Parameters.UserParameters
            Dim oUserParam As UserParameter
            Dim oPartNumProperty As Property
            Set oPartNumProperty = oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number")
            For Each oCell In oSheet.Range(sParamRange)
                For Each oUserParam In oUserParams
                    If oCell.Value = oPartNumProperty.Value Then
                        If Range("B1").Value = oUserParam.Name Then
                            oUserParam.Expression = oCell.Offset(0, 1).Value &amp;amp; oCell.Offset(0, 3).Value
                        End If
                    End If
                Next
            Next
        End If
    Next
End Sub&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 30 Jun 2020 04:20:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609150#M61448</guid>
      <dc:creator>tonythm</dc:creator>
      <dc:date>2020-06-30T04:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609277#M61449</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7812054"&gt;@WCrihfield&lt;/a&gt; , I have tried that single line in a part and is working. However, when executed in the codes I posted before, the macro seems it's runing at the assembly level. Any way to force a macro to run in an assembly occurrence?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 06:12:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609277#M61449</guid>
      <dc:creator>isidro.nunez</dc:creator>
      <dc:date>2020-06-30T06:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609279#M61450</link>
      <description>&lt;P&gt;when you want to use:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="color: #800080;"&gt;iLogicVb&lt;/SPAN&gt;.&lt;SPAN style="color: #800080;"&gt;RunRule&lt;/SPAN&gt;(&lt;SPAN style="color: #008080;"&gt;"PartA:1"&lt;/SPAN&gt;, &lt;SPAN style="color: #008080;"&gt;"ruleName"&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;SPAN style="color: #008080;"&gt;"PartA:1"&lt;/SPAN&gt; - it is occurrence name inside assembly from wchich you run rule.&lt;/P&gt;&lt;P&gt;so in your code you should change:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;iLogicVb.RunRule(oOccDoc.DisplayName, RuleName)&lt;/LI-CODE&gt;&lt;P&gt;to&lt;/P&gt;&lt;LI-CODE lang="general"&gt;iLogicVb.RunRule(oOcc.Name, RuleName)&lt;/LI-CODE&gt;&lt;P&gt;and it should be ok.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 06:15:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609279#M61450</guid>
      <dc:creator>marcin_otręba</dc:creator>
      <dc:date>2020-06-30T06:15:06Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609283#M61451</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/8622703"&gt;@tonythm&lt;/a&gt; , thanks for the code, but how I use it in my case? I have an unknown number of components in each assembly, and in some case, there are auxiliary sub-assemblies. I need to run a macro that is working right now and run another ilogic rule after the macro run.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 06:16:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609283#M61451</guid>
      <dc:creator>isidro.nunez</dc:creator>
      <dc:date>2020-06-30T06:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609294#M61452</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1734991"&gt;@marcin_otręba&lt;/a&gt; , I fix that but the InventorVb.RunMacro is still running in assembly level, so the rule is not in the occurrence. Thats why I need to run the macro before.&lt;/P&gt;&lt;P&gt;I have pieces without ilogic rules on them, so I need to create them with that macro.&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, 30 Jun 2020 06:25:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609294#M61452</guid>
      <dc:creator>isidro.nunez</dc:creator>
      <dc:date>2020-06-30T06:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609312#M61453</link>
      <description>&lt;P&gt;what this macro actually do ?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 06:37:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609312#M61453</guid>
      <dc:creator>marcin_otręba</dc:creator>
      <dc:date>2020-06-30T06:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609317#M61454</link>
      <description>&lt;P&gt;Check this one:&lt;/P&gt;&lt;P&gt;&lt;A href="https://adndevblog.typepad.com/manufacturing/2015/11/pass-parameters-to-a-vba-macro-from-an-ilogic-rule.html" target="_blank"&gt;https://adndevblog.typepad.com/manufacturing/2015/11/pass-parameters-to-a-vba-macro-from-an-ilogic-rule.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you can have parameter doc as document in your macro and pass it to it using oocc.definition.document.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 06:40:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609317#M61454</guid>
      <dc:creator>marcin_otręba</dc:creator>
      <dc:date>2020-06-30T06:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609327#M61455</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1734991"&gt;@marcin_otręba&lt;/a&gt;the macro does the following:&lt;/P&gt;&lt;P&gt;-Read the rules .txt files from a server.&lt;/P&gt;&lt;P&gt;-Create iLogic rules in the part and paste the codes from the server. If there was rules, it updates them.&lt;/P&gt;&lt;P&gt;-Create the parameters needed for the imported rules.&lt;/P&gt;&lt;P&gt;-Set the event triggers for all the rules as needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 06:47:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609327#M61455</guid>
      <dc:creator>isidro.nunez</dc:creator>
      <dc:date>2020-06-30T06:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609328#M61456</link>
      <description>&lt;P&gt;I will try this, thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 06:49:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609328#M61456</guid>
      <dc:creator>isidro.nunez</dc:creator>
      <dc:date>2020-06-30T06:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609332#M61457</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9046101"&gt;@isidro.nunez&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You should be know Part Number of part in Assy. You place them into new file assy(include only part) for refer to input parameter. After that use excel file run macro.&lt;/P&gt;&lt;P&gt;Excel vba control everything you need.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 06:51:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609332#M61457</guid>
      <dc:creator>tonythm</dc:creator>
      <dc:date>2020-06-30T06:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609479#M61458</link>
      <description>&lt;P&gt;I removed some code for clarity and it quickly shows this code will not do what you want it to do:&amp;nbsp;process all components in the assembly (even sub-assemblies).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Sub Main()

GoThrough:
For Each oOcc In oDoc.ComponentDefinition.Occurrences

    'Get Document from Occurrence
    Dim oOccDoc As Document
    oOccDoc = oOcc.Definition.Document

    'Check if document is a part
    If oOccDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	oOccDoc = oOcc.Definition.Document
        &amp;lt;do something&amp;gt;

    'if the document is an assembly we need to run the same code in each occurrence of that assembly (we uses a goto function)
    Else If oOccDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
        oDoc = oOccDoc
        GoTo GoThrough
    End If
Next

End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lets say halfway through processing the occurrences in your&amp;nbsp;top assembly, you find an occurrence representing a sub-assembly. Through the lines 'oDoc = oOccDoc' and 'Goto GoThrough' you think you continue with the sub assembly, but even if that&amp;nbsp;would happen,&amp;nbsp;there is no code&amp;nbsp;to return back to the&amp;nbsp;top assembly, meaning the&amp;nbsp;occurrences below the sub-assembly in the top assembly are never processed.&lt;BR /&gt;&lt;BR /&gt;I deliberately stated 'you think' and 'even if that would happen' because what actually happens is that the line 'oDoc = oOccDoc'&amp;nbsp;messes up the loop created by 'For Each oOcc In oDoc.ComponentDefinition.Occurrences'.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I wonder why you want to go through all the occurrences and get their documents when it's possible to go through all documents directly. You can read a clear article about&amp;nbsp;accessing assembly components, including example code,&amp;nbsp;by Brian Ekins &lt;A title="article on accessing assembly components" href="https://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html" target="_blank" rel="noopener"&gt;here&lt;/A&gt;. It has helped me a lot.&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, 30 Jun 2020 08:28:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609479#M61458</guid>
      <dc:creator>_dscholtes_</dc:creator>
      <dc:date>2020-06-30T08:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609556#M61459</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5406798"&gt;@_dscholtes_&lt;/a&gt; , as I said before, that code is from &lt;A href="https://hoppend.nl/inventor.htm" target="_blank" rel="noopener"&gt;hoppend.nl&lt;/A&gt; , I just modified the minimun. I see the problem, but right now it's not running the macro, the main task of these rules.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you look at my original post, you can see that I have used both, occurrences and documents in assembly, but the macro is not running on part level, only on assembly level.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will try to modify the macro as suggested by &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1734991"&gt;@marcin_otręba&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 09:02:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9609556#M61459</guid>
      <dc:creator>isidro.nunez</dc:creator>
      <dc:date>2020-06-30T09:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9610067#M61460</link>
      <description>&lt;P&gt;You may need to change your macro from using ThisApplication.ActiveDocument to ThisDoc.Document.&lt;/P&gt;&lt;P&gt;Or perhaps you need to modify your Macro to accept a variable, then pass the part document to the Macro as you would a reference within a Sub or Function.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 13:12:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9610067#M61460</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2020-06-30T13:12:44Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9610159#M61461</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7812054"&gt;@WCrihfield&lt;/a&gt; , when I change ThisApplication.ActiveDocument to ThisDoc.Document, it gives me an error, "ThisDoc is not defined"&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Option Explicit

    Sub Importar_ilogic()
    
    Dim i As Object
    Set i = GetiLogicAddin(ThisApplication)
 
    Dim oDoc As Document
    Set oDoc = ThisDoc.Document
        
    Call Parametros
     &amp;lt;here the macro call other subs and functions&amp;gt;

   End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had before this code:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;    Dim oDoc As Inventor.Document
    Set oDoc = ThisApplication.ActiveDocument&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 13:50:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9610159#M61461</guid>
      <dc:creator>isidro.nunez</dc:creator>
      <dc:date>2020-06-30T13:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9610221#M61462</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9046101"&gt;@isidro.nunez&lt;/a&gt;&amp;nbsp;ThisDoc is used in iLogic (rules), not in VBA (macro). Your original code using ThisApplication.ActiveDocument is correct.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 14:14:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9610221#M61462</guid>
      <dc:creator>_dscholtes_</dc:creator>
      <dc:date>2020-06-30T14:14:44Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9610256#M61463</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5406798"&gt;@_dscholtes_&lt;/a&gt; , I just saw it in the help:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot_1.png" style="width: 594px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/790111iC9B9D0B05C90D2BA/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot_1.png" alt="Screenshot_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I tried a few week before to do it with iLogic, but I couldn't manage to create rules.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 14:27:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9610256#M61463</guid>
      <dc:creator>isidro.nunez</dc:creator>
      <dc:date>2020-06-30T14:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9610515#M61464</link>
      <description>&lt;P&gt;That's right. For some reason I was thinking if your Macro was a simple one that is just running some other external iLogic rules. My mistake.&amp;nbsp; But the second suggestion is still valid.&lt;/P&gt;&lt;P&gt;Can you share your other Macro codes here so we can see the full picture of what's going on.&lt;/P&gt;&lt;P&gt;We can most likely find a way to keep it all either in iLogic or all in VBA, to make it simpler for you.&lt;/P&gt;&lt;P&gt;Or, if sharing the code isn't possible, due to privacy or proprietary info concerns, you may be able to create a very simplified assembly, iLogic rule, &amp;amp; macro that we can all use to test, as a proof of concept.&lt;/P&gt;&lt;P&gt;I know you can pass variables and values back and forth between iLogic rules, between VBA macros. and between rules &amp;amp; macros.&lt;/P&gt;&lt;P&gt;Otherwise, I'm not sure how your macro can know which specific part within your active assembly you want it to run on.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 16:25:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9610515#M61464</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2020-06-30T16:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro in assembly occurrences</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9610608#M61465</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9046101"&gt;@isidro.nunez&lt;/a&gt;&amp;nbsp;If I understand correctly, you have a part file with a&amp;nbsp;rule in it. You don't want to open the part file to run the rule. You want to open an assembly containing that part and have a macro run this rule.&lt;BR /&gt;&lt;BR /&gt;This works for me:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Private Sub RunPartRule()

    'Set reference to open document
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveEditDocument
    
    'Check if it's an assembly. If so, quit
    If Not oDoc.DocumentType = kAssemblyDocumentObject Then Exit Sub
    
    'Initiate the iLogic component (required to run an rule)
    Dim iLogicAuto As Object
    Set iLogicAuto = GetiLogicAddin(ThisApplication)
    If (iLogicAuto Is Nothing) Then Exit Sub
    
    'Declaration
    Dim oRefDoc As Document
    
    'Go through each document in the assembly document
    For Each oRefDoc In oDoc.ReferencedDocuments
    
        'Check if it's a part document
        If oRefDoc.DocumentType = kPartDocumentObject Then
        
             'Run the rule named "Rule0" from within the part document
             iLogicAuto.RunRule oRefDoc, "Rule0"
        End If
    Next

End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above code requires the following sub&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Public Function GetiLogicAddin(oApplication As Inventor.Application) As Object
    Dim addIn As ApplicationAddIn
    On Error GoTo NotFound
    Set addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
    If (addIn Is Nothing) Then Exit Function
    addIn.Activate
    Set GetiLogicAddin = addIn.Automation
    Exit Function
NotFound:
End Function&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the macro "RunPartRule" in my openend test assembly, it successfully runs the rule "Rule0" which is in my test part file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, this code only processes the open assembly. It doesn't process sub assemblies. For this to happen, you need a recursive function. You can find an example in the link I posted earlier, but recursive functions&amp;nbsp;have been discussed in various blogs and&amp;nbsp;posts. Or just ask any of the helpful guys here.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 17:18:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/run-macro-in-assembly-occurrences/m-p/9610608#M61465</guid>
      <dc:creator>_dscholtes_</dc:creator>
      <dc:date>2020-06-30T17:18:19Z</dc:date>
    </item>
  </channel>
</rss>

