What's new

AI Scripting new tools into Alibre!

Ex Machina

Alibre Super User
I really wanted to have the Pipe Tool from Fusion360 in Alibre. What the tool does is this:

It creates a sweep without you making the profile for it. It can switch between a circular and a square profile and it can be solid or hollow with a constant thickness. That's it! But in jobs where a lot of piping work is required, this can cut the required geometry generation to almost half. And, I made a video on how I did it, and here it is.

As always, comments and opinions are always welcome as it helps me to improve in the future! And also, let me know which tool you'd like to have that is missing from Alibre and will you make a script for it, AI or otherwise.

Code:
# Alibre Script: Advanced Sweep (Single Sketch Method)
# Creates a solid or hollow sweep from a single profile sketch.

import sys

# Establish handles for the main Alibre objects
MyPart = CurrentPart()
Win = Windows()

# --- 1. Define and Display the Menu ---
Units.Current = UnitTypes.Millimeters

# Define the layout of the static dialog window
Options = []
Options.append(['Path Sketch', WindowsInputTypes.Sketch, None])
Options.append(['Profile Type', WindowsInputTypes.StringList, ['Circle', 'Square']])
Options.append(['Size (mm)', WindowsInputTypes.Real, 10.0])
Options.append(['Hollow', WindowsInputTypes.Boolean, False])
Options.append(['Thickness (mm)', WindowsInputTypes.Real, 1.0])

# Show the options dialog
Values = Win.OptionsDialog('Create Advanced Sweep', Options, 220)

# Exit the script if the user cancels the dialog
if Values is None or Values[0] is None:
  print "Operation cancelled or no path sketch selected."
  sys.exit()

# --- 2. Process Inputs ---
PathSketch = Values[0]
ProfileTypeIndex = Values[1]
ProfileSize = Values[2]
IsHollow = Values[3]
Thickness = Values[4]

# --- Define the Profile Plane (Works for Lines and Splines) ---
FirstFigure = PathSketch.Figures[0]
Is3DSketch = '3D' in PathSketch.GetType().Name

if hasattr(FirstFigure, 'GetPointAt'): # Spline logic
  if Is3DSketch:
    StartPoint3D = FirstFigure.GetPointAt(0.0)
    NextPoint3D = FirstFigure.GetPointAt(0.001)
  else:
    StartPoint2D = FirstFigure.GetPointAt(0.0)
    NextPoint2D = FirstFigure.GetPointAt(0.001)
    StartPoint3D = PathSketch.PointtoGlobal(StartPoint2D[0], StartPoint2D[1])
    NextPoint3D = PathSketch.PointtoGlobal(NextPoint2D[0], NextPoint2D[1])
else: # Line logic
  if Is3DSketch:
    StartPoint3D = FirstFigure.StartPoint
    NextPoint3D = FirstFigure.EndPoint
  else:
    StartPoint2D = FirstFigure.StartPoint
    NextPoint2D = FirstFigure.EndPoint
    StartPoint3D = PathSketch.PointtoGlobal(StartPoint2D[0], StartPoint2D[1])
    NextPoint3D = PathSketch.PointtoGlobal(NextPoint2D[0], NextPoint2D[1])

DirectionVector = [NextPoint3D[i] - StartPoint3D[i] for i in range(3)]
ProfilePlane = MyPart.AddPlane('SweepProfilePlane', DirectionVector, StartPoint3D)

# --- 3. Create a Single Profile Sketch ---
ProfileSketch = MyPart.AddSketch('SweepProfile', ProfilePlane)

# Draw the outer profile shape based on the index from the dropdown
if ProfileTypeIndex == 0: # Circle
  OuterSize = ProfileSize
  ProfileSketch.AddCircle(0, 0, OuterSize, False)
elif ProfileTypeIndex == 1: # Square
  OuterHalf = ProfileSize / 2.0
  ProfileSketch.AddRectangle(-OuterHalf, -OuterHalf, OuterHalf, OuterHalf, False)

# If hollow is checked, draw the inner profile ON THE SAME SKETCH
if IsHollow and Thickness > 0 and Thickness < (ProfileSize / 2.0):
  if ProfileTypeIndex == 0: # Circle
    InnerSize = ProfileSize - (Thickness * 2)
    ProfileSketch.AddCircle(0, 0, InnerSize, False)
  elif ProfileTypeIndex == 1: # Square
    InnerSize = ProfileSize - (Thickness * 2)
    InnerHalf = InnerSize / 2.0
    ProfileSketch.AddRectangle(-InnerHalf, -InnerHalf, InnerHalf, InnerHalf, False)

# --- 4. Perform the Sweep ---
# Regenerate the part to ensure the sketch (with one or two loops) is finalized
MyPart.Regenerate()

# Create the sweep feature using the single profile sketch
MyPart.AddSweepBoss('Sweep', ProfileSketch, PathSketch, False, MyPart.EndCondition.EntirePath, None, 0, 0, False)

print "Script finished."
 
Last edited:
Watched this and thought it was freaking cool. Gave me some ideas to try on my own. Great video. What are you going to blow our minds with next?
 
Hahahahahah! I watched the video and also thought it came out nice. The problem is that now I need to keep the momentum!!!

But I'm glad I gave you a new tool to get things done. That was the whole idea. And it's really a great use for AI this.

I'm so glad you like it man! I really am.
 
Try the Gemini agent in VS Code. The stub files work great in editors. Local LLM apps and models perform much better now.


* A library in the Alibre Script addon can point to the same folder in VS Code.


 
Last edited:
I think I saw the same thing demoed in SolidWorks a while back.
Yeah, completely possible. That's the beauty of it. Alibre's environment allows the creation of new tools and add-ons exactly like SW, Fusion, and Onshape. And now with AI, anyone can make the tools he wants to make and offer to the community.

Serious value added to both SW and Alibre. But Alibre's robust core, snappy interface and modelling kernel, and lower price makes it an infinitely better proposition than SW. I really don't know why Alibre does not have a huge market share in CAD software. I can't explain it. But it'll get there. I think it's picking up pace...
 
@Ex Machina I followed your lead. I had used the pocket hole script before in some of my designs. However the fact that it worked in metric always caused me grief. I wanted it to work in inches like I think most of the time for my designs. Looking at the script with my limited coding knowledge I couldn't figure it out. So, Gemini to the rescue. It made the changes so the script would work in inches. Ran into a glitch regarding the pockethole png image file, so I just deleted that line, didn't need it anyway. Then it developed an indexing error. It not only explained the error but told me how to fix it. Hot dog!! Now the script works in inches, and it has become a lot more useful to me. I am sure I will be using it in the future. Thanks to you. I had not even considered using AI to rewrite the script before. Oh the possibilities.
 
I tried that and ChatGPT quite a bit and GPT kept getting it wrong in pretty silly ways. I guess if you stick with it long enough, both will learn
 
Yeah, completely possible. That's the beauty of it. Alibre's environment allows the creation of new tools and add-ons exactly like SW, Fusion, and Onshape.

Alibre programming is only 10 to 20% of what Big CAD offers. For free/OSS, FreeCAD's nearly entire API is available.

What's not available to API/Scripting:

Sheet metal
2D drawings
PDM
Libraries
Publishing
Toolbox
BOM
Most of Alibre Expert features are not available.

What's available (still only a very small subset):

Querying data
Properties
Sketching
Part
Assembly
Parameter
Configuration
Import/Export methods
Miscellaneous properties and methods

Even within the supported areas Alibre programming is missing significant core functionality and depth in each area. High performance and professional grade features are missing. I'm working to improve what I can, but Alibre needs a complete overhaul to even come close to matching Big CAD and FreeCAD.

Why Gemini?

I like it as a second or third opinion. It's better at explaining and fixing problems I give it when another LLM fail.

I really don't know why Alibre does not have a huge market share in CAD software.

If the API had parity with Expert, I believe it would. This has been my view since I purchased Expert 15+ years ago. I started building a tank and pressure vessel piping and nozzle design tool. I soon realized it didn’t have all the API features of SolidWorks 2008, that I was using at work.
 
Rhino/Grasshopper, Excel and Autodesk wouldn't be what they are today without full customization, VBA and .NET (lisp,vb,cs,c++). The same is true for scripting and development ecosystems for Rhino/Grasshopper (food4rhino), Sketchup (extension warehouse), Autodesk (app store) and all the resellers selling third party addons and plugins.

No.. Alibre is more closer to 10% compared to anyone else.
 
Alibre's environment allows the creation of new tools and add-ons exactly like SW
If is so easy to add new tools for Alibre what's taking so long to get them developed. There are a few tools/features that could be added via scripting that have been submitted so long ago that I've forgotten what they are.

When I was working we had SolidWorks 2017 or 18 ( been a while so I don't recall). Anyway, we had an engineer that developed VB scripts for us. And it didn't take all that long for him to get the script done. We just added icons to a tool bar to run them. No special environment to "Launch" them from - the just became part of the workflow. And no diging thru directories to find the right script to run and then have to exit the environment. You get used to it but it seems kludgy.

As good as Alibre is it does have its work cut out to compete with some of the major programs.
 
We just added icons to a tool bar to run them. No special environment to "Launch" them from - the just became part of the workflow. And no diging thru directories to find the right script to run and then have to exit the environment. You get used to it but it seems kludgy.
I think the issue with Alibre and Scripting is that they were 2 separate applications and the integration has only been partially implemented. Scripting should, in my opinion, be much more integrated and seamless than it currently is ... but that's the downside of applications 'evolving' rather than being fully planned from day 1!

Scripting shouldn't be something that needs turning on/off.
Scripting should have the ability to assign a toolbar icon to run a particular script.

Just my 2c!
 
But I'm glad I gave you a new tool to get things done. That was the whole idea. And it's really a great use for AI this.
Went back and rewatched the video and the iterations necessary to get a preferred outcome. One thing that I think is missing is a mm/inch toggle to make it a global tool.
Great work! You're on a roll with all your latest videos.

Will it be uploaded to the forum Resources?
 
If is so easy to add new tools for Alibre what's taking so long to get them developed. There are a few tools/features that could be added via scripting that have been submitted so long ago that I've forgotten what they are.
I think the issue here is Quality Assurance. It is indeed so easy to add tools to Alibre. But when you're making the script, you don't have any Quality Expectations. When you pay for a software you do. I get that and I'll tell you why. I'll say the story that I must have said a thousand times but bear with me.

When I started my company, I was using Fusion. I started with it in 2017 when it was basically an open beta. Now, in 2021 I had a project that was huge for me. I was part of a remote team working for one of the largest companies on the planet. The product was handheld pyrometer that could go up to 1200°C. I was given the outer surface and I was supposed to make it injection ready and mount the electronics. We had specs for shock, drops, everything was supposed to be met. And Fusion wasn't having an of it. I fought it for 2-3 days just to get the surface thickened. Then I was working on the webbing and Fusion putting up a fight. Areal tough one... At the time I had Alibre on trial for 15 days and hadn't even touched it.

I fire it up, I think to myself "OK, I'm in Inventor..." lol, and I import the surface. It thickened it immediately.
I sketch the webbing the way I liked it, Extrude Thin, Up To Next, and 1.5seconds later I had my complete Webbing!!!
I boolean in the metal chassis I had designed for the "guts", 2 seconds later, I had my webbing conform to my chassis PERFECTLY!!!

Never looked back since. Now, I only open Fusion when I need to make a video comparing it to Alibre. lololololololol

The purpose of this story is Quality Assurance. It was the Rock-Solid robustness of Alibre's existing tools that brought me over. And that made me the money to buy Expert while STILL ON THE TRIAL!!! Alibre Paid for ITSELF while still on TRIAL for me!

So yeah, I wish they were adding tools faster, but I'm kind of aren't wishing it too, if you know what I mean.

Went back and rewatched the video and the iterations necessary to get a preferred outcome. One thing that I think is missing is a mm/inch toggle to make it a global tool.
Great work! You're on a roll with all your latest videos.

Will it be uploaded to the forum Resources?

I saw your message and added the code to the OP. Uhm, confession time... I don't know how to add it to the forum resources. And yeah would make it better. Or even better, reading the units of the document!!! But yeah, easy to do with AI at this point.
 
Last edited:
I don't know how to add it to the forum resources.
I've always just hit the Green Add Resources button, it's just a file upload.
And yeah would make it better. Or even better, reading the units of the document!!! But yeah, easy to do with AI at this point.
I was thinking either reading the file properties and use them but there is possibility that while working in mm you need to create something in Inches, or visa versa.
I'm no programmer but was able to stumble thru changing a copy of the Pocket Hole Creator script to make it accept inch inputs. I just don't have the wizardry to add a drop-down or radio button for selecting inch or mm.
 
@HaroldL you are smarter than me. I couldn't figure out how to modify the Pocket Hole Creator script to work in inches so I followed @Ex Machina and went to AI. It reworked the script and helped me solve an error to get it working in inches. Now I have it working in inches for me to use.
 
@Ex Machina your script is using the builtin Window class. For addons I can't use that. @NateLiquidGravity made SelectionListBox that's perfect for addons. I need to integrate it into my process. I'll post when ready. I have a new bot GitHub account, I'll let work on this to test it.

The scripts AI make isn’t the best, especially as complexity increases. Functions and classes can be required for certain cases where code reuse is better or necessary. Giving any LLM code to fix is the best way to use them with Alibre Script. Python vs Iron Python and versioning is something to look out for. This addon is Iron Python 3, Alibre Script addon uses 2.7.10. Use AI to help learn Python, that's my take. Ask it to explain the addon source code. But again, as complexity increases GenAI benefits start to diminish significantly.

Here is an example of PipeTool.py with functions:


Addon source:


1755545867612.png
 
Back
Top