Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic.Automation Loading Error

7 REPLIES 7
Reply
Message 1 of 8
hexer_abbahex
290 Views, 7 Replies

iLogic.Automation Loading Error

Hello,

When I try to access iLogic.Automation, I get the following exception

"Export of type library: The type library is not registered. (Exception from HRESULT: 0x80131165)"

I would like to get the surfaces by name and then position the two components by surface to surface.

 

iLogicAddIn.Automation.GetNamedEntities(pFaceName, ObjectTypeEnum.kFaceObject);

 

Does anyone know which library is missing?

 

#region imports

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using Inventor;
using System.Runtime.CompilerServices;

#endregion

namespace autodesk_framework
{
    internal class Program
    {
        #region properties

        public static Application InventorApplication { get; set; }
        public static AssemblyDocument CurrentDocument { get; set; }
        public static ApplicationAddIn iLogicAddIn { get; set; }
        private static string ProjectFolder { get; set; }

        #endregion

        #region methods

        static void Main(string[] args)
        {
            ProjectFolder = @"C:\Users\Inventor Projekte\";

            try
            {
                StartInventorApplication();

                CreateAutomation();

                LoadCADAssembly();                
               
                CreateParallelConstraint_Test();          
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex}");
            }

            Console.ReadLine();
        }

        private static void StartInventorApplication()
        {
            try
            {
                InventorApplication = (Application)Marshal.GetActiveObject("Inventor.Application");
            }
            catch (COMException)
            {
                Type ApplicationType = Type.GetTypeFromProgID("Inventor.Application");

                InventorApplication = (Application)Activator.CreateInstance(ApplicationType);
                InventorApplication.Visible = true;
            }

            Console.WriteLine("Inventor Application started");
        }

        private static void LoadCADAssembly()
        {
            string CADAssemblyPath = System.IO.Path.Combine(ProjectFolder, "BG_1.iam");

            CurrentDocument = (AssemblyDocument)InventorApplication.Documents.Open(CADAssemblyPath, true);

            Console.WriteLine($"Model '{CADAssemblyPath}' loaded successfully.");

            CurrentDocument.Activate();
        }      

        private static void CreateParallelConstraint_Test()
        {           
            ComponentOccurrence TargetComponent = GetComponentByName(CurrentDocument, "Bauteil1:1");
            ComponentOccurrence InsertComponent = GetComponentByName(CurrentDocument, "Bauteil4:1");

//Error
            if (iLogicAddIn.Automation != null)
            {

            }

            CreateParallelConstraint(TargetComponent, InsertComponent);
        }

        private static void CreateParallelConstraint(ComponentOccurrence pTargetComoponent, ComponentOccurrence pInsertComponent)
        {
            Face InsertComponentFace = GetFaceByName(pInsertComponent, "unten");
            Face TargetComponentFace = GetFaceByName(pTargetComoponent, "oben");

            if (InsertComponentFace == null || TargetComponentFace == null)
            {
                Console.WriteLine("Required planar faces not found.");

                return;
            }

            MateConstraint NewMateContraint = CurrentDocument.ComponentDefinition.Constraints.AddMateConstraint(InsertComponentFace, TargetComponentFace, 0, InferredTypeEnum.kNoInference, InferredTypeEnum.kNoInference, Type.Missing, Type.Missing);            

            //MateConstraint offsetConstraint = CurrentDocument.ComponentDefinition.Constraints.AddMateConstraint(InsertComponentFace,    TargetComponentFace,    distanceInInternalUnits,     InferredTypeEnum.kInferredLine,    InferredTypeEnum.kInferredLine,    0,    0);

            Console.WriteLine("Parallel constraint added between specified faces.");
        }

        private static Face GetFaceByName(ComponentOccurrence pComponent, string pFaceName)
        {                      
//Error
            NameValueMap namedEntities = iLogicAddIn.Automation.GetNamedEntities(pFaceName, ObjectTypeEnum.kFaceObject);

            if (namedEntities.Count > 0)
            {
                return namedEntities[1] as Face;
            }

            return null;
        }

        private static void CreateAutomation()
        {
            string iLogicAddinGuid = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}";            

            try
            {
                iLogicAddIn = InventorApplication.ApplicationAddIns.get_ItemById(iLogicAddinGuid);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (iLogicAddIn != null)
            {
                if (!iLogicAddIn.Activated)
                {
                    iLogicAddIn.Activate();
                }                    
            }
        }

        private static ComponentOccurrence GetComponentByName(AssemblyDocument pDocument, string pComponentName)
        {
            foreach (ComponentOccurrence CurrentComponent in pDocument.ComponentDefinition.Occurrences)
            {
                if (CurrentComponent.DefinitionDocumentType == DocumentTypeEnum.kPartDocumentObject || CurrentComponent.DefinitionDocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
                {
                    if (CurrentComponent.Name.Equals(pComponentName))
                    {
                        return CurrentComponent;
                    }
                }

                if (CurrentComponent.DefinitionDocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
                {
                    return GetComponentByName(CurrentComponent.Definition.Document, pComponentName);
                }
            }

            Console.WriteLine($"component '{pComponentName}' not found");

            return null;
        }     

        #endregion
    }
}

 

Tags (3)
Labels (1)
7 REPLIES 7
Message 2 of 8
WCrihfield
in reply to: hexer_abbahex

Hi @hexer_abbahex.  C# is not my thing, but you can review the following online help page for more information about some of the things you may be missing.

https://help.autodesk.com/view/INVNTOR/2025/ENU/?guid=GUID-32B66838-22E4-4A0A-B5BB-862350C76B36 

...under Imports

Likely the ones you may need a reference to are:

Autodesk.iLogic.Interfaces

Autodesk.iLogic.Runtime

Autodesk.iLogic.Types

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 8

hexer_abbahex_0-1722959947419.png

I added all references and copied the dlls to my project folder. But it dont work, and the using path is the install folder of Autodesk. I think all dlls should be in this folder.

Message 4 of 8
JelteDeJong
in reply to: hexer_abbahex

I have these references for iLogic in Inventor 2023. (you might need some other references for other Inventor versions)

JelteDeJong_0-1722968140835.png

For this to work you don't have to copy the dlls to yourproject folder.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 5 of 8

I add more dlls 

 

hexer_abbahex_0-1722982829577.png

but now I get following error if I want access to 

 

 

            iLogicAutomation MyAutomation = iLogicAddIn.Automation;

            if (MyAutomation != null)
            {

            }

System.IO.FileNotFoundException: "The file or assembly "netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" or a dependency of it was not found. The system cannot find the specified file."

I think now I have a problem, because my project is a .net Framework 4.8 console application.

Message 6 of 8

Now I created a .net 7.0 console project to use Autodesk Inventor 2025 from an external application. I can handle components and so on but I cant use iLogic

hexer_abbahex_0-1723042651237.png

If I use the dynamic type, I can read out the objects with the names, but I cannot access them because I always get an error due to missing properties.
But if I use the type NamedEntities instead of dynamic I get another error.

hexer_abbahex_1-1723042895308.png

 



Message 7 of 8
WCrihfield
in reply to: hexer_abbahex

Hi @hexer_abbahex.  This is not really a 'solution' but more like a suggested workaround.  I am not sure if you are aware of this, but what you are trying to do with the GetNamedEndities method can be done without the help of iLogic.  We can use the AttributeManager object, which we can get from any Document object (Document.AttributeManager), then search for "iLogicEntityNameSet" and "iLogicEntityName" as the AttributeSet name and Attribute names to find.  Then the Attribute.Value will contain the name you assigned to them.  And the AttributeSet will be attached to the object (Object.AttributeSets collection).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 8

ok, I will try it

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report