Listing iLogic rules using C#

Top  Previous  Next

Remember to have Autodesk.iLogic.Automation.dll as a reference...

 

 

iLogic-reference

This works:

 

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

           Inventor.ApplicationAddIn addin = null;

           try

           {

               addin = m_Inventor.ApplicationAddIns.get_ItemById(iLogicAddinGuid);

           }

           catch

           {

               MessageBox.Show("Could not get iLogic object");

           }

 

           if (addin != null)

           {

               if (!addin.Activated)

               {

                   addin.Activate();

               }

 

               dynamic _iLogicAutomation = addin.Automation;

               _iLogicAutomation.CallingFromOutside = true;

 

               dynamic AllRules = _iLogicAutomation.Rules(m_Inventor.ActiveDocument);

 

               if (AllRules == null)

               {

                   MessageBox.Show("There are no rules in this document");

                   return;

               }

 

               foreach (/*iLogicRule*/ dynamic ThisRule in AllRules)

               {

                   MessageBox.Show("name of rule = " + ThisRule.Name);

               }

           }

 

 

It was modified from code found here:

 

 

https://forums.autodesk.com/t5/inventor-customization/call-ilogic-from-net-c-inventor-2018/m-p/8522694/highlight/true#M93226

 

 

Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)