Interesting Tech Projects
Posts tagged scripting

Python Scripting with Alibre Design
Apr 3rd
ADScript makes it easy to use Alibre Design with Python scripting. For example creating a new part:
1 | Test = Part( "Test" ) |
We can get access to planes in the design workspace, for example:
1 | XYPlane = Test.GetPlane( "XY-Plane" ) |
Once we have a part and plane we can create a sketch on the plane:
1 | MySketch = Test.AddSketch( "MySketch" , XYPlane) |
Adding to the sketch is easy:
1 | MySketch.AddCircle( 0 , 0 , 10 , False ) |
Now we can extrude it:
1 | Object = Test.AddExtrudeBoss( "Object" , MySketch, 5 , False ) |

Python CAD Scripting
Jun 24th
FreeCAD supports Python as a scripting language which allows the creation of 3D parts based on variables. This is great for building libraries which support customizable part creation.
As a first attempt I created the following test script. When executed in FreeCAD 0.13 it creates a rod 10mm x 10mm x 50mm with a notch in it. It then removes a cube measuring 4mm x 4mm x 4mm from one end.
Here is what the hierarchy looks like:
And here is the script:
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | import FreeCAD, FreeCADGui, Part App = FreeCAD doc = App.activeDocument() rodbasepts = list () rodbasepts.append(App.Vector( 0 , 0 , 0 )) rodbasepts.append(App.Vector( 0 , 10 , 0 )) rodbasepts.append(App.Vector( 10 , 10 , 0 )) rodbasepts.append(App.Vector( 10 , 0 , 0 )) rodbasepts.append(App.Vector( 6 , 0 , 0 )) rodbasepts.append(App.Vector( 6 , 2 , 0 )) rodbasepts.append(App.Vector( 4 , 2 , 0 )) rodbasepts.append(App.Vector( 4 , 0 , 0 )) rodbasepts.append(App.Vector( 0 , 0 , 0 )) rodbase = Part.makePolygon(rodbasepts) rodbasefilled = Part.Face(rodbase) rod = rodbasefilled.extrude(App.Vector( 0 , 0 , 50 )) #rod.Placement = App.Placement(App.Vector(10, 0, 0), App.Rotation(0, 0, 0, 1)) rodpart = doc.addObject( "Part::Feature" , "rod" ) rodpart.Shape = rod cubebasepts = list () cubebasepts.append(App.Vector( 0 , 0 , 0 )) cubebasepts.append(App.Vector( 0 , 4 , 0 )) cubebasepts.append(App.Vector( 4 , 4 , 0 )) cubebasepts.append(App.Vector( 4 , 0 , 0 )) cubebasepts.append(App.Vector( 0 , 0 , 0 )) cubebase = Part.makePolygon(cubebasepts) cubebasefilled = Part.Face(cubebase) cube = cubebasefilled.extrude(App.Vector( 0 , 0 , 4 )) cubepart = doc.addObject( "Part::Feature" , "cube" ) cubepart.Shape = cube cut = doc.addObject( "Part::Cut" , 'Rod minus cube' ) cut.Base = rodpart cut.Tool = cubepart rodpart.ViewObject.hide() cubepart.ViewObject.hide() doc.recompute() |
To use create a new Part and then copy and paste the script into the Python Console inside FreeCAD.