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%\Autodesk\ApplicationPlugins" 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>\Bin\Public 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
#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
[
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
<!-- Type attribute is same as Type registry key
(Standard, Translator, Plugin (Server only) -->
<Addin Type="Standard">
<!-- Should be the same as the "GuidAttribute" in MyClrAddIn.h -->
<ClassId>{3543165F-7F19-4614-8842-572A5EBE9549}</ClassId>
<ClientId>{3543165F-7F19-4614-8842-572A5EBE9549}</ClientId>
<!-- Both of the following fields should be translated.
NO OTHER FIELDS SHOULD BE TRANSLATED! -->
<DisplayName>MyClrAddIn</DisplayName>
<Description>MyClrAddIn</Description>
<!-- Assumes that MyClrAddIn.dll is in the same folder as the *.addin file -->
<Assembly>MyClrAddIn.dll</Assembly>
<SupportedSoftwareVersionGreaterThan>17..</SupportedSoftwareVersionGreaterThan>
<LoadOnStartUp>1</LoadOnStartUp>
<Hidden>0</Hidden>
</Addin>
Here is the source code of the project:
https://github.com/adamenagy/Inventor-AddInWithCLR