What's new

adding to addons

simonb65

Alibre Super User
3rd Party add-on will have an installer that puts the addon in the right place. When Alibre starts it checks it's Add-On directory and presents the available add-on in the Add-On manager for the user to enable (i.e. load at start-up).

For Custom Add-Ons, all the info you need is in the https://www.alibre.com/forum/index.php?forums/add-on-development.28/ forum area, including how to write them (C, C++, C#) and what files need to go in the Add-On directory (and their contents) for Alibre to see them.

There are also a few Add-On examples which you can download if you want to see what's involved, plus a few users (including myself) have posted snippets of custom add-ons within that forum area.
 

danwrnr11

Member
Custom or bought 3rd Party Add-Ons?
I have followed the links you posted and have a good understanding now of what the addon manager can do! My nest question is I have found that Blender "open source" handles alibre models quite well. Having said that I would like to have blender ope as does Keyshot when you select "render" within Alibre.
Regards,
Dan Warner,
wood working professional
 

simonb65

Alibre Super User
I have followed the links you posted and have a good understanding now of what the addon manager can do! My nest question is I have found that Blender "open source" handles alibre models quite well. Having said that I would like to have blender ope as does Keyshot when you select "render" within Alib
Well, v25 (in Beta right now) has the ability to export models as an .obj and .mtl file for direct import into Blender (See New v25 OBJ Export). An Add-On just needs to be a simple single button that calls the export function (that's if Alibre have included it in the API ??), then start a Blender shell process passing the exported file names as Blenders input command line arguments.

If you follow any of the examples, it's quite trivial. There is one example of a 'generic' external application launcher if you search through the forum (sorry, I can't remember where or who posted that one).
 

simonb65

Alibre Super User
Looking into this, you'll need to export the OBJ and MTL as say ...

{filename}.obj
{filename}.mtl


call bender from Alibre with a command line of 'something' like ...

blender.exe -b {filename}.blend -P importOBJMTL.py

Where 'filename' is the name of your part/assembly for ease of keeping it unique and something the script can get hold of (i.e. the scene name).

This creates a blender scene, and executes a python script (also written by the add-on to the same directory as the obj and mtl files) that would need to do the import the OBJ and MTL file (of the same name as the .blend scene). I don't think you can import OBJ and MTL directly from the blender command line, but it's doable!
 

simonb65

Alibre Super User
@danwrnr11, just to help a little bit more, here is a bit of test code that is in C# and is in the button pressed handler for an Add-On menu item. As I'm running v24 at the moment, I'm not sure what the v25 API calls are for saving the OBJ and MTL files, but this uses a simple text.obj I exported from Blender just to get Alibre to start and run an import script in Blender. Hope this small token helps you ...

C#:
switch (e.Session.SessionType)
{
    case ADObjectSubType.AD_PART:
    case ADObjectSubType.AD_ASSEMBLY:
        IADDesignSession ds = e.Session as IADDesignSession;

        string directory = @"D:\sandbox_alibre\";    // TODO : make a temporary sub-directory named after the part/assembly name.
        string name = "test"; // ds.Name;

        // TODO : Sanitise 'name' to make it filepath friendly!

        // check if Alibre is
        if (m_VersionMajor >= BLENDER_MIN_MAJOR_VERSION)         // BLENDER_MIN_MAJOR_VERSION needs setting to 25 and AlibreX.dll needs to be from v25
        {
            // Export the OBJ file
            //ds.ExportOBJ(directory + name + ".obj");          // TODO : Need v25 to get the API syntax

            // Export the MTL file
            //ds.ExportMTL(directory + name + ".mtl");        // TODO : Need v25 to get the API syntax

            // Create the Blender python script
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("import bpy");
            sb.AppendLine("");
            //sb.AppendLine("name = 'test'");         // TODO : determine 'name' from obj file in the same directory as this script
            //sb.AppendLine("");
            sb.AppendLine("# Import OBJ");
            sb.AppendLine("bpy.ops.import_scene.obj( filepath = '" + directory.Replace("\\", "\\\\") + name + ".obj' )");

            // Save python script to same direcrtory as OBJ and MTL files
            using (StreamWriter writer = new StreamWriter(directory + "import_from_alibre.py"))
            {
                writer.Write(sb.ToString());
            }

            // Open Blender and run the python script to import the OBJ file
            Process p = new Process();
            p.StartInfo.FileName = m_BlenderShellOpenCommand.Replace("\"", "").Replace("%1", "").Trim();
            p.StartInfo.Arguments = "--python \"" + directory + "import_from_alibre.py\"";
            p.Start();
        }
        break;


    default:
        Debug.WriteLine("ExportBlender : Session type '" + e.Session.SessionType + "' not supported!");
        break;
}

You can add to the script to set up a camera, lighting, etc and render the scene too!
 
Top