bolsover
Senior Member
I've lately been experimenting with writing an Add On for Alibre V24.
I thought it might be helpful to share some of my experience.
The first thing I should note is that what I have been working on is just for my own interest - but very happy to share with others.
AlibreX documentation
There is quite a lot missing from the AlibreX documentation with respect to Add On development and the absence of worked examples makes life quite difficult!
My starting point was to look over the AlibreX documentation. The first challenge I faced was that the Add-On introduction only references C++ code for the all important AlibreAddOn class.
I wanted to write code using C#. I'm not particularly experienced with C# - but it is a lot closer to Java - where I have 20+ years experience developing desktop applications for manufacturing.
Decompile AlibreX and AlibreAddOn
Lucky for me, I have a licence for Jetbrains DotPeek whicth includes a decompiler allowing me to peek into the Alibre Code (which appears to be written in C#) to see how things are done internally.
Trawling through the Alibre code, I discovered that it is possible to write an Add-On using C# but that there are a couple of prerequisites.
The first thing I found is that the AlibreDesignAddOn .adc file requires an undocumented change.
Original Alibre .adc:
The above needs a modification:
Note <DLL type="Managed" and specificationVersion="2"
The type="Managed" appears to instruct Alibre to load a C# .NET compatible Add-On - without this flag my code simply would not work.
I'm not too sure what specificationVersion="2" does.
The AlibreAddOn class
The next important job is to create the AlibreAddOn class with implementations of the three methods discussed in the Alibre documentation:
Two important things to note about the above: the namespace and the class name - BOTH need to match the above for the code to be loaded by Alibre - ask me how I know!!
I've only actually added any real custom code to the AddOnLoad method. This loads a custom IAlibreAddOn where all the heavy lifting for an AddOn application starts - I'll dig a little deeper into that file in another post.
db
I thought it might be helpful to share some of my experience.
The first thing I should note is that what I have been working on is just for my own interest - but very happy to share with others.
AlibreX documentation
There is quite a lot missing from the AlibreX documentation with respect to Add On development and the absence of worked examples makes life quite difficult!
My starting point was to look over the AlibreX documentation. The first challenge I faced was that the Add-On introduction only references C++ code for the all important AlibreAddOn class.
I wanted to write code using C#. I'm not particularly experienced with C# - but it is a lot closer to Java - where I have 20+ years experience developing desktop applications for manufacturing.
Decompile AlibreX and AlibreAddOn
Lucky for me, I have a licence for Jetbrains DotPeek whicth includes a decompiler allowing me to peek into the Alibre Code (which appears to be written in C#) to see how things are done internally.
Trawling through the Alibre code, I discovered that it is possible to write an Add-On using C# but that there are a couple of prerequisites.
The first thing I found is that the AlibreDesignAddOn .adc file requires an undocumented change.
Original Alibre .adc:
XML:
<AlibreDesignAddOn specificationVersion="1" friendlyName="My AddOn">
<Author name="MyName" link="http://URL"/>
<DLL loadedWhen="Startup" location="MyAddOnName.dll"/>
<Copyright> My CopyRight Information</Copyright>
<Icon location="MyAddOn.ico"/>
<Menu text="My AddOn"/>
<Description> XYZ </Description>
<Workspace type="Part"/>
<Property name="Identifier" value="{DA8322C2-CE32-450C-2E43-5CG77C52D4B4}"/>
</AlibreDesignAddOn>
The above needs a modification:
Note <DLL type="Managed" and specificationVersion="2"
XML:
<AlibreDesignAddOn specificationVersion="2" friendlyName="My AddOn">
<Author name="MyName" link="http://URL"/>
<DLL type="Managed" loadedWhen="Startup" location="MyAddOnName.dll"/>
<Copyright> My CopyRight Information</Copyright>
<Icon location="MyAddOn.ico"/>
<Menu text="My AddOn"/>
<Description> XYZ </Description>
<Workspace type="Part"/>
<Property name="Identifier" value="{DA8322C2-CE32-450C-2E43-5CG77C52D4B4}"/>
</AlibreDesignAddOn>
The type="Managed" appears to instruct Alibre to load a C# .NET compatible Add-On - without this flag my code simply would not work.
I'm not too sure what specificationVersion="2" does.
The AlibreAddOn class
The next important job is to create the AlibreAddOn class with implementations of the three methods discussed in the Alibre documentation:
C#:
using System;
using AlibreAddOn;
using AlibreX;
using Bolsover;
namespace AlibreAddOnAssembly
{
public static class AlibreAddOn
{
private static IADRoot alibreRoot;
private static IntPtr parentWinHandle;
private static DataBrowserForAlibreImpl AlibreAddOnInterface;
public static void AddOnLoad(IntPtr hwnd, IAutomationHook pAutomationHook, IntPtr unused)
{
alibreRoot = (IADRoot) pAutomationHook.Root;
parentWinHandle = hwnd;
AlibreAddOnInterface = new DataBrowserForAlibreImpl(alibreRoot, parentWinHandle);
}
public static void AddOnInvoke(
IntPtr hwnd,
IntPtr pAutomationHook,
string sessionName,
bool isLicensed,
int reserved1,
int reserved2)
{
}
public static void AddOnUnload(
IntPtr hwnd,
bool forceUnload,
ref bool cancel,
int reserved1,
int reserved2)
{
}
public static IAlibreAddOn GetAddOnInterface()
{
return (IAlibreAddOn) AlibreAddOnInterface;
}
}
}
Two important things to note about the above: the namespace and the class name - BOTH need to match the above for the code to be loaded by Alibre - ask me how I know!!
I've only actually added any real custom code to the AddOnLoad method. This loads a custom IAlibreAddOn where all the heavy lifting for an AddOn application starts - I'll dig a little deeper into that file in another post.
db