Calling iLogic from C# |
Top Previous Next |
Remember to have Autodesk.iLogic.Automation.dll as a reference...
Here is an example, the dynamic keyword is important apparently:
using System; using System.Windows.Forms; using Inventor;
namespace OInventor { public partial class Form1 : Form { static Inventor.Application m_Inventor; // static Inventor.ApplicationAddIn m_AddIn;
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();
dynamic _iLogicAutomation1 = addin.Automation;
Document oCurrentDoc1 = m_Inventor.ActiveDocument;
_iLogicAutomation1.RunRule(oCurrentDoc1, "Pippo"); } } } }
Note that you have to have included the Autodesk.iLogic.Automation reference in your product references:
|
Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)