Running iLogic rules from other programs.

Running iLogic rules from other programs.

oransen
Collaborator Collaborator
1,465 Views
11 Replies
Message 1 of 12

Running iLogic rules from other programs.

oransen
Collaborator
Collaborator

I'd like to know how to do this, in C# probably. This page...

 

https://help.autodesk.com/view/INVNTOR/2019/ENU/?guid=GUID-1DF09784-4ABD-4BA8-914B-3172866244EA

 

tells me this:

Automation interface to access parameters and rules...

iLogic provides an automation interface. You can use this interface from Inventor VBA, or VB6 or NET code to access parameters and rules.

The class iLogicAutomation enables this capability.

In a VBA or VB project, you use it as a late-bound type (declared as an Object) without adding a reference. Because it is not a full COM object, you cannot browse its methods.

 

...but does not show me any examples. I downloaded the 400MB samples package suggested on another page, but it is just samples of parts and assemblies.

 

There must be a place of examples of running iLogic rules from another program, but I just can't find it.

 

TIA

 

Owen Ransen

 

 

 

 

 

0 Likes
Accepted solutions (1)
1,466 Views
11 Replies
Replies (11)
Message 2 of 12

bradeneuropeArthur
Mentor
Mentor

Why not using Complete VBA or complete vb.net.

This will be easier!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 12

oransen
Collaborator
Collaborator

You didn't really reply yo my question...!

 

I prefer not to use VBA because VB(A) is a horrible language. Very popular, but horrible.

0 Likes
Message 4 of 12

bradeneuropeArthur
Mentor
Mentor

Sorry but you did not understand my answer.

I would not use i-logic at all for this case.

Use either complete VBA or Complete Vb.net (You are not familiar with Vb.net I assume)

 

Why do you find it a horrible language, only because I am curious.

It will have more  possibilities for you then VBA or I-logic for you, is my opinion.

 

Regards

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 12

oransen
Collaborator
Collaborator

"Why do you find it a horrible language, only because I am curious.

I will have more possibilities then VBA or I-logic for you, is my opinion."

 

This is all only my opinion... VBA It is based on a very old language called BASIC which was designed not for actual applications but for teaching. And it grew and it grew and it grew. C# has learned from the errors of C++ (which in my opinion has also become a monster. )

 

I would never build a big project with VB, but I would with C#.

 

I find C# more elegant, but again, it is only my opinion. VBA wins because it is very very easy to get something going, and then you get hooked!

 

 

 

0 Likes
Message 6 of 12

oransen
Collaborator
Collaborator

"I would not use i-logic at all."

 

I agree, nor would I. But there are cases in which a lot of nitty gritty knowledge is included in already written and running i-Logic rules which would take a long time to put into another system.

 

Plus if the i-Logic is already being used daily why recreate what someone else has already done?

 

 

0 Likes
Message 7 of 12

oransen
Collaborator
Collaborator

I've found this...

 

https://adndevblog.typepad.com/manufacturing/2013/04/call-ilogic-from-net.html

 

I'll postthe full code here if I get it to go...

0 Likes
Message 8 of 12

oransen
Collaborator
Collaborator
       // entrance of iLogic

        Autodesk.iLogic.Automation.iLogicAutomation _iLogicAutomation =

            (Autodesk.iLogic.Automation.iLogicAutomation)addin.Automation;

        Document oCurrentDoc = m_inventorApplication.ActiveDocument;

 
        // From here onwards I think the names of types have changed ....
        Autodesk.iLogic.Interfaces.iLogicRule myRule = null;
        //dump all rules
        foreach (Autodesk.iLogic.Interfaces.iLogicRule eachRule in _iLogicAutomation.get_Rules(oCurrentDoc))
        {
            if (eachRule.Name == "MyRule")
            {
                myRule = eachRule;
                //list the code of rule to the list box
                MessageBox.Show( myRule.Text);
                break;
            }
        }
        if (myRule != null)
            _iLogicAutomation.RunRule(oCurrentDoc, "MyRule");
    }

The above code is the last part of the example shown here:

 

https://adndevblog.typepad.com/manufacturing/2013/04/call-ilogic-from-net.html

 

but it does not compile because I think the names of types and functions has changed (since 2013!)

 

Can anyone translate it into 2021 Inventor 2019 code?

 

Tia,

 

Owen

 

 

0 Likes
Message 9 of 12

bradeneuropeArthur
Mentor
Mentor

Can you share the complete code include the i-logic part of it?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 10 of 12

oransen
Collaborator
Collaborator

The complete code is in the link...

0 Likes
Message 11 of 12

bradeneuropeArthur
Mentor
Mentor
Accepted solution

maybe this will help you when you translate it

Imports Inventor

Public Sub New(currentInvApp As Inventor.Application)
        _invApp = currentInvApp
End Sub

Public Sub RuniLogicRule(ByVal RuleName As String)

        Dim iLogicAddinName As String = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"

        Dim iLogicAddIn As Inventor.ApplicationAddIn = Nothing

        Try
            iLogicAddIn = _invApp.ApplicationAddIns.ItemById(iLogicAddinName)
        Catch ex As Exception

        End Try

        If iLogicAddIn IsNot Nothing Then
            If iLogicAddIn.Activated = False Then
                iLogicAddIn.Activate()
            End If

            Dim _iLogicAutomation As Object
            
            _iLogicAutomation = iLogicAddIn.Automation

            Dim oCurrentDoc As Document
            oCurrentDoc = _invApp.ActiveDocument

            _iLogicAutomation.RunRule(oCurrentDoc, RuleName)

        End If

    End Sub

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 12 of 12

oransen
Collaborator
Collaborator

Thanks...I translated what you proposed and it almost worked. After some more digging I found that I had to use dynamic to declare the iLogicAutomation.

 

I have some iLogic in an IAM called "Pippo" and this is the code which allows me to call it from an external C# program:

 

using System;
using System.Windows.Forms;
using Inventor;

namespace OInventor
{
    public partial class Form1 : Form
    {
        static Inventor.Application m_Inventor;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            m_Inventor = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");


            int iNumDocs = m_Inventor.Documents.Count;
            MessageBox.Show("There are " + iNumDocs.ToString() + " documents");

            string iLogicAddinGuid = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}";

            Inventor.ApplicationAddIn addin = null;

            try
            {
                // try to get iLogic addin
                addin = m_Inventor.ApplicationAddIns.get_ItemById(iLogicAddinGuid);
            }
            catch
            {
                return;
            }


            if (addin != null)
            {
                // activate the addin
                if (!addin.Activated)
                    addin.Activate();

                // The dynamic keyword here is important...
                dynamic _iLogicAutomation1 = addin.Automation;

                Document oCurrentDoc1 = m_Inventor.ActiveDocument;

                _iLogicAutomation1.RunRule(oCurrentDoc1, "Pippo");
            }
        }
    }
}

 

 

Thanks again for your help and suggestions.

 

This is the link which pointed out the dynamic keyword thingy:

 

https://forums.autodesk.com/t5/inventor-customization/call-ilogic-from-net-c-inventor-2018/m-p/85226...