Add iLogic to C#

Add iLogic to C#

Daan_M
Collaborator Collaborator
686 Views
3 Replies
Message 1 of 4

Add iLogic to C#

Daan_M
Collaborator
Collaborator

Hi, 

 

I have a problem adding iLogic and also the dll's give me a warning, dont know what i'm doing wrong...

.

void AddiLogic()
        {
            string MyRuleName = "rulename";
            string iLogicAddinGuid = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}";
            ApplicationAddIn iLogicAddin;
            object iLogicAutomation = null;
            try
            {
                iLogicAddin = _invApp.ApplicationAddIns.ItemById[iLogicAddinGuid];
                iLogicAutomation = iLogicAddin.Automation;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to access iLogic addin " + ex.Message);
            }

            try
            {
                iLogicAutomation.RunRule(oDoc, MyRuleName);
            }
            catch
            {
                MessageBox.Show("There is no rule called " + MyRuleName);
            }
        }

 

vraag 8.JPG

 

0 Likes
Accepted solutions (1)
687 Views
3 Replies
Replies (3)
Message 2 of 4

ianteneth
Advocate
Advocate

Hi @Daan_M,

 

I think the error is telling you that you need to define the type of the iLogicAutomation object. In the line below you are declaring iLogicAutomation as a generic object. And the generic Object class doesn't have a method called RunRule. What is the type of iLogicAutomation? Replace the word 'object' in the line below with the actual type of the iLogicAutomation object. I hope this helps!

object iLogicAutomation = null;

 

You could alternatively replace the above line with this maybe?

var iLogicAutomation;

 

Message 3 of 4

Daan_M
Collaborator
Collaborator

Thank you for the reply, i changed it and get the following error in the line where i declare the local variable:


" Error CS0818 Implicitly-typed variables must be initialized " 

 

 void AddiLogic()
        {
            string MyRuleName = "cmdRead";
            string iLogicAddinGuid = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}";
            ApplicationAddIn iLogicAddin;
            var iLogicAutomation; //<- HERE
            try
            {
                iLogicAddin = _invApp.ApplicationAddIns.ItemById[iLogicAddinGuid];
                iLogicAutomation = iLogicAddin.Automation;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to access iLogic addin " + ex.Message);
            }

            try
            {

                iLogicAutomation.Runrule(oDoc, MyRuleName);
            }
            catch
            {
                MessageBox.Show("There is no rule called " + MyRuleName);
            }
        }

 

0 Likes
Message 4 of 4

ianteneth
Advocate
Advocate
Accepted solution

I found a link to an earlier post that had this problem. This line seems to be the fix? Try using "dynamic" instead of "var".

 

dynamic iLogicAutomation = null;

 

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