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
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
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; } } }; }



Leave a Reply