How to LoadAddIn/LoadPackageContents in Inventor?

How to LoadAddIn/LoadPackageContents in Inventor?

ricaun
Advisor Advisor
179 Views
2 Replies
Message 1 of 3

How to LoadAddIn/LoadPackageContents in Inventor?

ricaun
Advisor
Advisor

Hello I'm new in Invertor API and have a lot of experience with Revit API.

 

I wonder if there are some native method like LoadAddIn or LoadPackageContents inside Inventor API.

 

LoadAddIn(string fileName) : Loads add-ins from the given manifest file. 

LoadPackageContents(packageContentsPath) : Loads add-ins from the given packageContents.xml file. 

 

If someone know some similar method or way would be great.

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
Accepted solutions (2)
180 Views
2 Replies
Replies (2)
Message 2 of 3

marcin_otręba
Advisor
Advisor
Accepted solution

hi,

 

I am affraid there is not.

I use locator functionality instead:

Private loc As New Locator()
Dim currentPath As String = Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly().Location) & "\Lib"
loc.InstallLocator(currentPath)
  Public Class Locator
        Private _path As String

        Public Sub New()

        End Sub

        Public Sub InstallLocator(ByVal path As String)
            _path = path
            AddHandler AppDomain.CurrentDomain.AssemblyResolve, AddressOf AssemblyResolve
        End Sub

        Private Function AssemblyResolve(ByVal sender As Object, ByVal args As ResolveEventArgs) As Assembly
            Dim position As Integer = args.Name.IndexOf(",")
            If position > -1 Then
                Try
                    Dim assemblyName As String = args.Name.Substring(0, position)
                    Dim assemblyFullPath As String = String.Empty

                    'look in main folder
                    assemblyFullPath = _path & "\" & assemblyName & ".dll"
                    If File.Exists(assemblyFullPath) Then
                        Return Assembly.LoadFrom(assemblyFullPath)
                    End If
                Catch ex As Exception
                    System.Diagnostics.Debug.WriteLine(ex.Message)
                End Try
            End If
            Return Nothing
        End Function
    End Class

 

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 3 of 3

ricaun
Advisor
Advisor
Accepted solution

@marcin_otręba wrote:

I am affraid there is not.


I kinda need something more native to make the application inside the ApplicationAddIns list and show in the Add-In Manager Reference.

 

To find the Guid class and create an instance is not hard to make:

using Inventor;
using System;
using System.Runtime.InteropServices;
using System.Reflection;

public static class InventorAddinLoader
{
    public static ApplicationAddInServer CreateApplication(Assembly assembly, Guid guid)
    {
        var exportedTypes = assembly.GetExportedTypes();
        foreach (var type in exportedTypes)
        {
            if (type.GetInterface(typeof(ApplicationAddInServer).FullName) == null)
                continue;

            if (type.GetCustomAttribute<GuidAttribute>() is GuidAttribute guidAttribute)
            {
                if (new Guid(guidAttribute.Value) != guid)
                    continue;

                return assembly.CreateInstance(type.FullName) as ApplicationAddInServer;
            }
        }
        return default;
    }
}

 

After looking in the Add-In Manager UI don't think is possible to load a addin when Inventor is open, only when startup.

 

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes