Inventor Add-In using C++/CLR

By Adam Nagy

Philippe already created a sample mixed-managed (C++/CLR) add-in that you can have a look at. But I thought it could be useful to list the steps to achieve that. Instead of creating a C++ Inventor add-in using the Inventor Add-In wizard, adding .NET support to it, and separating the generated code from the managed parts using #pragma unmanaged /#pragma managed blocks, it's easier to create a C++/CLR Class Library and implement your ApplicationAddInServer in .NET.

1) Create the "C++/CLR Class Library" – preferably inside "%APPDATA%AutodeskApplicationPlugins" to make your life easier

MyClrAddIn

2) Create a "x64" platform for the project and keep that active

Inside the "Configuration Manager" dialog, under "Active solution platform" select "<New…>" and add the "x64" platform

X64

3) Reference "Autodesk.Inventor.Interop.dll"

Click "PROJECT" >> "References…" and browse to "<Inventor install folder>BinPublic Assemblies" and add "Autodesk.Inventor.Interop.dll"

4) Inside the same dialog box also add a reference to "System.Windows.Forms" just so that we can show a message box from our code later on

5) Implement the "ApplicationAddInServer" class

// MyClrAddIn.h  #pragma once  using namespace System; using namespace System::Runtime::InteropServices; using namespace System::Windows::Forms; using namespace Inventor;  namespace MyClrAddIn {   public ref class StandardAddInServer : public ApplicationAddInServer   {   public:     StandardAddInServer(void)     {      }      virtual void Activate(ApplicationAddInSite^ addInSiteObject, bool firstTime)     {       MessageBox::Show("Add-In Loading");      }      virtual void Deactivate()     {       MessageBox::Show("Add-In Unloading");      }      virtual void ExecuteCommand(int CommandID)     {     }      virtual property Object^ Automation     {       // If you want to return an interface to another client of this addin,       // implement that interface in a class and return that class object        // through this property       Object^ get()       {         return nullptr;       }     }   }; }

5) Create a GUID and a ProgId for the class and make it ComVisible

namespace MyClrAddIn {   [     ProgId("MyClrAddIn.StandardAddInServer"),     GuidAttribute("3543165F-7F19-4614-8842-572A5EBE9549"),      ComVisible(true)   ]   public ref class StandardAddInServer : public ApplicationAddInServer   {     // etc...

Note: you can use Visual Studio's "Create GUID" dialog for creating a new GUID

7) Create an *.addin file inside your solution's folder with name "" and content  

{3543165F-7F19-4614-8842-572A5EBE9549}   {3543165F-7F19-4614-8842-572A5EBE9549}       MyClrAddIn   MyClrAddIn       MyClrAddIn.dll    17..   1   0

Here is the source code of the project:
https://github.com/adamenagy/Inventor-AddInWithCLR

Share this:

Like this:

Like Loading…

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading