Try to run a ilogicRule from a exe c# program

Try to run a ilogicRule from a exe c# program

edson_luiz86
Enthusiast Enthusiast
225 Views
1 Reply
Message 1 of 2

Try to run a ilogicRule from a exe c# program

edson_luiz86
Enthusiast
Enthusiast

I create a c# progra that i want to call a rule in my ipt part.

In my reference I add
Autodesk.iLogic.Interfaces
Autodesk.iLogic.Runtime
Autodesk.Inventor.Interop

I set the 3 referenes with Interop Types = false. and copy to output folder = true

this is my InventorApp code

 

using Autodesk.iLogic.Interfaces;
using Inventor;
namespace InventorHSA
{
	public class PartDocument
	{
		Inventor.PartDocument _partDocument;
		Inventor.Application _invApp { get
			{
				return _partDocument.Parent as Inventor.Application;
			}
		}

		public string FullFileName
		{
		get { return _partDocument.FullFileName; }
		}

		public PartDocument(Inventor.PartDocument partDocument)
		{
		_partDocument = partDocument;
		}
		
		public void RuniLogicRule(string ruleName)
        {
            //iLogic is also an addin which has its guid
            string iLogicAddinGuid = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}";

            Inventor.ApplicationAddIn addIn = _invApp.ApplicationAddIns.ItemById[iLogicAddinGuid];

            var iLogicAuto = addIn.Automation;
            Inventor.Document _doc = _partDocument as Inventor.Document;
            IiLogicAutomation automation = iLogicAuto as IiLogicAutomation;
            automation.RunRule(_doc,ruleName);
        }
	}
}

 

But when I compile I got the error "Problem on generate the manifest, there isn't possible load Autodesk.iLogic.Types.resourses.dll" or one of their dependencies

I simplify my code to this snipet,
My question is there is a other way to run a rule in my part document?

0 Likes
Accepted solutions (1)
226 Views
1 Reply
Reply (1)
Message 2 of 2

edson_luiz86
Enthusiast
Enthusiast
Accepted solution

I found this topic and gave a inside for solution for my case
https://forums.autodesk.com/t5/inventor-programming-ilogic/call-ilogic-from-net-c-inventor-2018/td-p...
the solution is change the line
var iLogicAutomation = addIn.Automation;
to
dynamic iLogicAutomation = addIn.Automation;

my new code is below

using Autodesk.iLogic.Interfaces;
using Inventor;
namespace InventorHSA
{
	public class PartDocument
	{
		Inventor.PartDocument _partDocument;
		Inventor.Application _invApp { get
			{
				return _partDocument.Parent as Inventor.Application;
			}
		}

		public string FullFileName
		{
		get { return _partDocument.FullFileName; }
		}

		public PartDocument(Inventor.PartDocument partDocument)
		{
		_partDocument = partDocument;
		}
		
		public void RuniLogicRule(string ruleName)
        {
            //iLogic is also an addin which has its guid
            string iLogicAddinGuid = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}";

            Inventor.ApplicationAddIn addIn = _invApp.ApplicationAddIns.ItemById[iLogicAddinGuid];

            dynamic iLogicAuto = addIn.Automation;// var iLogicAuto = addIn.Automation; line changed
            Inventor.Document _doc = _partDocument as Inventor.Document;
            //IiLogicAutomation automation = iLogicAuto as IiLogicAutomation; removed this line to prevent error
            automation.RunRule(_doc,ruleName);
        }
	}
}
0 Likes