Run external rule without an open document?

Run external rule without an open document?

erichter
Advocate Advocate
1,761 Views
13 Replies
Message 1 of 14

Run external rule without an open document?

erichter
Advocate
Advocate

I generally write my iLogic rules in external .vb files which allows for quicker editing outside of Inventor's VB editor. I have one such script that opens documents. Since it is external, I can quickly edit it to change the documents that I want to open. I would like to be able to run this from the Inventor home screen without having to open a document first. However, the only way I know how to run an external script requires an active document to be open. If I try this without an open document, I get the error: "Object reference not set to an instance of an object."

 

Is there anyway to run an external rule without an open document?

 

GetiLogicAddin(ThisApplication).RunExternalRule ThisApplication.ActiveDocument, ExternalRulePath

 

0 Likes
Accepted solutions (2)
1,762 Views
13 Replies
Replies (13)
Message 2 of 14

WCrihfield
Mentor
Mentor

I haven't tried it yet, but you could probably run it from Visual Studio, if you had it all set-up right, and Inventor was running.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 14

erichter
Advocate
Advocate

That's the exact opposite of what I am trying to do. I found a workaround. Script that opens external rules will start a new part file if no documents are open then close it when done.

0 Likes
Message 4 of 14

aelqabbany
Advocate
Advocate

@erichter Could you please share your script here so that we can all benefit?

0 Likes
Message 5 of 14

greggeorgi
Contributor
Contributor
Accepted solution

In my usage, I do this all the with VBA and Addins as it is easier to deploy ilogic rules to users on network drives.

 

If no documents are open, then the ilogic addin is not 'initilizied' it seems.

 

My solution is to open a empty part document, run the rule, then close the document

 

dim doc = thisapplication.documents.add(documenttypeenum.kpartdocument, <optional Path to template>, true)

'run external ilogic rule

doc.close(true) 'close without saving or prompting to save

 

to run the rule, first access the ilogic addin automation object.

 

I do not have inventor open currently nor the time right now to find the rest of the information, so the above is psuedo code for what is required.

0 Likes
Message 6 of 14

erichter
Advocate
Advocate
Accepted solution

Thanks. I ended up doing something similar.

If ThisApplication.ActiveDocument Is Nothing Then
ThisApplication.Documents.Add kPartDocumentObject
iLogicAuto.RunExternalRule ThisApplication.ActiveDocument, oPath
ThisApplication.Documents.VisibleDocuments.Item(1).Close (True)
Else
iLogicAuto.RunExternalRule ThisApplication.ActiveDocument, oPath
End If
0 Likes
Message 7 of 14

Maxim-CADman77
Advisor
Advisor

FYI, since 2025 there is no need to use any tricks - it's possible to run iLogic rule (with ribbon button associated) without having any document open..

Please vote for Inventor-Idea Text Search within Option Names

Message 8 of 14

JBerns
Advisor
Advisor

@Maxim-CADman77,

 

Would you have any example code you could share?

 

I used @Curtis_Waguespack add-in template to create an add-in for Inventor 2025. (some edits required for compatibility)

 

I copied the original Run_External_iLogic_Rule.vb and modified it to not require a document argument:

 

Module Run_External_iLogic_Rule_NoDoc

    Public Sub RunExternalRule(ByVal ExternalRuleName As String)

        Try

            ' The application object.
            Dim addIns As ApplicationAddIns = g_inventorApplication.ApplicationAddIns()

            ' Unique ID code for iLogic Addin
            Dim iLogicAddIn As ApplicationAddIn = addIns.ItemById("{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}")

            ' Starts the process
            iLogicAddIn.Activate()

            ' Executes the rule
            '  iLogicAddIn.Automation.RunExternalRule(g_inventorApplication.ActiveDocument, ExternalRuleName)
            iLogicAddIn.Automation.RunExternalRule(ExternalRuleName) ' << ERROR HERE
...

 

I call the new sub when the button executes:

'This is the code that does the real work when your command is executed.
Sub Run_ExternalRule()
    MessageBox.Show("This command creates a new assembly from the ZeroDoc environment via External Rule.", "Create New Assembly", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Run_External_iLogic_Rule_NoDoc.RunExternalRule("\\EngServer\inventor_data\Support\iLogic\CreateNewAssemblyFromZeroDoc.iLogicVb")
End Sub

 

Currently, an error occurs when the code gets to the 'RunExternalRule' line.

 

Again, any examples you could share that show how to run an external rule from the ZeroDoc environment would be appreciated.

 

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 9 of 14

Maxim-CADman77
Advisor
Advisor

Your question puzzles me.
It is nothing to do with coding (no special code  to share).
You just use Customize command to create custom ribbon button using your external iLogic rule as command (in ZeroDoc Panel), and then just press the button when there is no document active.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 10 of 14

JBerns
Advisor
Advisor

How would you share the customization at an enterprise-level?

Again, this is new territory for me, so I may be overlooking a simple solution.

I thought add-ins would be best for a team of users.

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 11 of 14

Curtis_Waguespack
Consultant
Consultant

@Maxim-CADman77, I get this when I run an external rule at the zero document state.

Are you saying that you do not see this message?

 

Curtis_Waguespack_3-1753912901619.png

 

My rule: ( nothing specific to a document)

Curtis_Waguespack_0-1753912825902.png

 

Set up 

Curtis_Waguespack_4-1753913000584.png

 

Use 

Curtis_Waguespack_1-1753912878183.png

 

 

EESignature

0 Likes
Message 12 of 14

Maxim-CADman77
Advisor
Advisor

Guys, I confirm - it doesn't work the way I reported it on 8th of June.

Seems like I've mistaken "no open documents" with "no document active" (home page is active) which was not deliberate.

Thus we still need to use the trick with VBA-macro to have the ribbon button to run iLogic when there is no documents open.
Sorry for have wasted your time.

Please vote for Inventor-Idea Text Search within Option Names

Message 13 of 14

Curtis_Waguespack
Consultant
Consultant

@Maxim-CADman77 , no apologies needed. Thanks for the confirmation.

 

 

EESignature

Message 14 of 14

JBerns
Advisor
Advisor

@Maxim-CADman77 ,

 

Ackn. Thanks for clarifying.

 

For now, I am starting with a few buttons on the ZeroDoc environment to build some of our equipment. Eventually, I want to build a Windows Form interface from which the user will select the equipment type and component type. After clicking the Generate button, a new assembly is created based on a template. Next, the new assembly and its unique components are saved based on job number and classification.

 

JBerns_0-1753972214721.png

I am hoping the transition from a ribbon button to a form selection and button click are not difficult.

I appreciate the support of the forum community to achieve this goal. Guidance is always welcome.

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes