What's new

Add-on development using C#

Hello everyone

I've been trying to develop an Add-on for Alibre Design using C#. My goal ist to develop an add-on which can start a wpf.net window which can access certain Alibre session attributes(filename, filepath, ...).
Since I'm not very experienced using the Alibre API, I've read the Add-on Introduction in the API documentation. But as it turns out, the documentation is not yet completed for C#.
The documentation states that all add-ons share the same basic infrastructure. Then it proceeds describing the "Three important functions", which are only described in c++.

I've used the following forum post for reference, which has been of great help. I've basically copied his AlibreAddOn class into my project.

Now to my question.
I have the following code:

C#:
using System;
using AlibreX;
using ZDB_connector.View;

namespace AlibreAddOnAssembly
{
    public static class AlibreAddOn
    {
        private static MainWindow _mainWindow;

        public static void AddOnLoad(IntPtr hwnd, IAutomationHook pAutomationHook, IntPtr unused)
        {
            _mainWindow = new MainWindow();
            _mainWindow.Show();
        }

        public static void AddOnInvoke(
            IntPtr hwnd,
            IAutomationHook pAutomationHook,
            string sessionName,
            bool isLicensed,
            int reserved1,
            int reserved2)
        {
        }

        public static void AddOnUnload(
            IntPtr hwnd,
            bool forceUnload,
            ref bool cancel,
            int reserved1,
            int reserved2)
        {
        }
    }
}

In this example we can see the three important functions: AddOnLoad, AddOnInvoke and AddOnUnload.
If I compile this and run it in Alibre, it only works once. After closing, it is not possible to open it again.
I cannot get this code to work consistently.

I would be grateful for a few tips or maybe even a skeleton on how this file should be.
 

bolsover

Senior Member
@daniel.greil
I'm probably one of the few members to have actually got a C# add-on working...
You can read some of my progress in this post: Adventures..

All my code is open source and available on GitHub: UtilitiesForAlibre

It would be helpful to know what you want to achieve - there are quite a few limitations and pitfalls when it comes to coding for Alibre!

I'm not sure WPF is a good fit with Alibre - I used WinForms.

Have a look over my code - it may give you some useful insights.

VERY important the .ADC file MUST have '<DLL type="Managed"' when working with C#!!

Good luck

David
 
@daniel.greil
I'm probably one of the few members to have actually got a C# add-on working...
You can read some of my progress in this post: Adventures..

All my code is open source and available on GitHub: UtilitiesForAlibre

It would be helpful to know what you want to achieve - there are quite a few limitations and pitfalls when it comes to coding for Alibre!

I'm not sure WPF is a good fit with Alibre - I used WinForms.

Have a look over my code - it may give you some useful insights.

VERY important the .ADC file MUST have '<DLL type="Managed"' when working with C#!!

Good luck

David
Hello David

Thanks for the useful advice.
Finally, I settled for Windows Forms instead of WPF. This is because WPF would return errors more often than Windows Forms.
If you don't mind, I will use the basic structure of the UtilitiesForAlibre.cs file in your project linked in your Post above.

Thanks again for the Help

Daniel
 

bolsover

Senior Member
@daniel.greil
No problem. I found it useful to examine the structure of Alibre Script add-on. If you have a decompiler (such as that found in Jetbrains ReSharper) you can examine the inner workings of several alibre. dll. I also found looking into the WizoGrid add-on helpful - it does not work with V22 and higher but if interested, you can bypass the version checks quite easily. It's a shame it is no longer supported by the author.
 
Top