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
}
}
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
(Not an Autodesk Employee)
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.
I have these references for iLogic in Inventor 2023. (you might need some other references for other Inventor versions)
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.
Blog: hjalte.nl - github.com
I add more dlls
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.
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
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.
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
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.