Skip to content

FreePySCAD script window

Merill edited this page Oct 30, 2020 · 8 revisions

The goal of this windows is to allow the user to generate quickly simple geometries, without having to switch to a full-blown CAD software, save, open. If you need to create a complicated object (more than 5 minutes to create), the real CAD software should be the preferred choice.

How it works

You write the tree with functions separated by ',' like union()(cube(x=1,y=3,z=1), cube(3,1,1).move(-1,2)) to create a 'T', a bit like in openscad. Then, you click on the 'generate' button and this script is send to the FreeCAD python console (you must have entered the path to the bin directory of your FreeCAD installation, at least 0.19). The FreeCAD software will send back an object file that will be imported automatically in your platter. In the current implementation, all objects in your platter will be replaced by the generated object(s)

How to write

You have access to basic primitive object like cube and cylinder.
example: cylinder(r=5,h=2)
You can move and rotate them.
example: cylinder(r=5,h=2).rotate(x=90)
You can create union, intersection, and difference (cut) of objects.
example: cut()( cylinder(r=5,h=2).rotate(x=90), cylinder(r=2,h=2) )
Each union, intersection or cut is also an object.
Each object at root level will create an object in the platter.
All available functions are documented here

how to write python code

As it's a python script, you can also write plain python function, object and loops.
But to be able to do that, you have to say what portion of the code is the object collection and what is the python code. This is done with the scene().redraw() function.function.
Example:

uni = union("lines")
for pos in range(0,4) :
    uni.add( cube(1,10,1).move(x=2*pos) )
scene().redraw(
  uni
)

Label

All functions can take a "name" parameter. It's useful for the root union/cut, so you can name your object.
example: cut("my object")( cube(10), cylinder(1,10) )

The script window

Some help has been included in the little window.

First, you have auto-completion, automatically or by typing ctrl+space.

Second, you have a little help windows to tell you the possible parameters you can enter in the function (if any). All parameters can be used with the form x=12, but it's not mandatory if there are no '=' in the help window: cube(size) means that you can call it like cube(10) or cube(size=10) ; cylinder(d=,h=) means that the only way is to use cylinder(d=2,h=3).

The script window tries to correct errors, like when you forgot a ','. It's very work-in-progress, as ideally, it has to really understand the written tree to tell you where there is an error, but it's not done yet. If you have something that really bother you, don't hesitate to open an issue.

shortcuts

  • crtl + space : Autocompletion
  • ctrl + escape : exit
  • ctrl + s : Quicksave (if already saved/loaded)
  • ctrl + maj + s : Save as
  • ctrl + n : Clear
  • ctrl + g | F5 : Generate