Message 1 of 8
iLogic.Automation Loading Error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
}
}