Call iLogic from .NET

By Xiaodong Liang

iLogic has been widely used nowadays. Sometimes, to achieve some requirements, we need to combine Inventor API and iLogic, e.g. call a rule from an addin.

The interfaces for iLogic exists with <Inventor Installation Path>binAutodesk.iLogic.Automation.dll and Autodesk.iLogic.Interfaces.dll. The iLogicAutomation is the entrance of iLogic.

The following is a small demo on how to dump all rules of the current document and execute one rule.

void _buttonDef1_OnExecute(NameValueMap Context)    {         //iLogic is also an addin which has its guid        string iLogicAddinGuid = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}";             Inventor.ApplicationAddIn addin = null;        try        {            // try to get iLogic addin            addin =                    m_inventorApplication.ApplicationAddIns.get_ItemById(iLogicAddinGuid);        }        catch        {            // any error...        }             if (addin != null)        {            // activate the addin            if (!addin.Activated)                addin.Activate();                 // entrance of iLogic            Autodesk.iLogic.Automation.iLogicAutomation _iLogicAutomation =                (Autodesk.iLogic.Automation.iLogicAutomation)addin.Automation;                 Document oCurrentDoc = m_inventorApplication.ActiveDocument;                 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;              &#160
; }            }            if (myRule != null)                _iLogicAutomation.RunRule(oCurrentDoc, "MyRule");        }    }

Comments

2 responses to “Call iLogic from .NET”

  1. Kari Holgarsson Avatar
    Kari Holgarsson

    Could you make a similar post for VB.NET?

  2. I try to use your code bat sent me this exception
    Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ‘No se puede convertir el tipo ‘System.__ComObject’ a ‘Autodesk.iLogic.Automation.iLogicAutomation’.’

Leave a Reply to CarlosCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading