I am new to creating .NET AddIns for Inventor so this is probably an easy answer.
As a test I created an AddIn that simply displays a form and added a button that outputs "Hello" when clicked. The AddIn loads fine in Inventor(see Loaded.png). When I debug the AddIn it does not seem as though any code in the "Activate" function gets ran. This is where I want to create the control definitions and add the ribbon button correct? Am I missing something here?
StandardAddInServer.vb Code is below:
Imports Inventor Imports System.Runtime.InteropServices Imports Microsoft.Win32 Namespace TestAddIn <ProgIdAttribute("TestAddIn.StandardAddInServer"), _ GuidAttribute("856d6ece-8c6a-41c4-a904-b96f02162008")> _ Public Class StandardAddInServer Implements Inventor.ApplicationAddInServer #Region "ApplicationAddInServer Members" Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate ' This method is called by Inventor when it loads the AddIn. ' The AddInSiteObject provides access to the Inventor Application object. ' The firstTime flag indicates if the AddIn is loaded for the first time. ' Initialize AddIn members. - Not used ' m_InventorApplication = addInSiteObject.Application MsgBox("Test") ' TODO: Add ApplicationAddInServer.Activate implementation. ' e.g. event initialization, command creation etc. End Sub
Note that I am not using m_Inventor Application and instead using the global g_InventorApplication as suggested by Brian in another thread.
End Namespace Public Module Globals Public g_InventorApplication As Inventor.Application End Module
The startup form is set as Form1. (see Project.png)
In the compile window, make sure the make COM visible is check.
Also make sure the .addin file is with the other addin files, usually in programdata folder.
Make sure the path in the addin file is correct.
I don't see where the COM visible option is. I am using VS 2010. See the attached SS.
Also does the AddIn go in:
C:\Users\rob\AppData\Roaming\Autodesk\Inventor 2014\Addins
or
C:\Users\rob\AppData\Roaming\Autodesk\ApplicationPlugins\TestAddIn
I believe it can go in either.
Check if you have the C:\ProgramData\Autodesk\Inventor 2014\Addins and make sure the addin file is NOT in the ROAMING folders.
See the pict for the COM.
I moved the AddIn to the ProgramData location you suggested.
The COM visible option is checked.
What is the path for the Build Output location under compile?
The AddIn help file suggests putting the .addin file and .dll file in the "Roaming" folder for drag and drop deployment. See the attached screen capture. The AddIn loads fine following this method.
In the activate function of many AddIn examples there is a variable for the client ID denoted as m_ClientID
this is usually defined as:
m_ClientID = AddInGuid(GetType(StandardAddInServer))
What is the code for the AddInGuid function? I could not find this defined anywhere.
I can get the value for the client ID and set it but would like to use the function.
I'm trying to create an add-in from some VBA code myself and figuring this all out as i go.
That AddInGuid function took me some time too. It is found in the VBAtoAddIn.pdf. If you check this post and download the sample files, open the ClassSample project in there. At the bottom of StandardAddInServer.vb you'll find:
' This property uses reflection to get the value for the GuidAttribute attached to the class. Public Shared ReadOnly Property AddInGuid(ByVal t As Type) As String Get Dim guid As String = "" Try Dim customAttributes() As Object = t.GetCustomAttributes(GetType(GuidAttribute), False) Dim guidAttribute As GuidAttribute = CType(customAttributes(0), GuidAttribute) guid = "{" + guidAttribute.Value.ToString() + "}" Finally AddInGuid = guid End Try End Get End Property
So there.
(A late reply, but who knows, maybe someone starts googleing and ends up here like i did.)