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>\bin\Autodesk.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;
}
}
if (myRule != null)
_iLogicAutomation.RunRule(oCurrentDoc, "MyRule");
}
}