Friday, November 5, 2010

Creating Cross Sections of Parts in HeeksPython

Ok, I worked out a scheme for creating a cross sectional view of a simple assembly in HeeksPython. I altered my dxf_to_heekspython script slightly to let the sketches have unique IDs. Then it's possible to create objects out of them and do CSG operations to the unique objects.
Here is a sample script:

import HeeksPython as cad
import sys
import dxf_to_heekspython
from math import pi

a1 = 90*(pi/180)

units = 25.4 #inch units
part1 = "cad.setcolor(0,0,0)\n"
part1 = dxf_to_heekspython.gen_heekspython_entities(r1,1)
part1 = part1 +"cad.scale(sketch1,0,0,0,units)\n"
part1 = part1 +"cad.setcolor(255,255,255)\n"
part1 = part1 +"cad.revolve(sketch1,360)\n"
part1 = part1 +"cup = cad.getlastobj()\n"
part2 = "cad.setcolor(0,0,0)\n"
part2 = dxf_to_heekspython.gen_heekspython_entities(r2,2)
part2 = part2 +"cad.scale(sketch2,0,0,0,units)\n"
part2 = part2 +"cad.setcolor(0,255,0)\n"
part2 = part2 +"cad.revolve(sketch2,360)\n"
part2 = part2 +"sleeve = cad.getlastobj()\n"


c1= '/home/dan/Documents/drawings/cutaway.dxf'
cut = dxf_to_heekspython.gen_heekspython_entities(c1,3)
cut = cut + "cad.scale(sketch3,0,0,0,units)\n"
cut = cut + "cad.revolve(sketch3,90)\n"
cut = cut + "cutter = cad.getlastobj()\n"
cut = cut + "cad.rotate(cutter,0,0,0,1,0,0,a1)"


Here is the assembly:

Just prior to importing these dxf files into HeeksPython I had also added fillets to all the corners in Caduntu (yes, this works well now Ries!). So now I can work in my favorite 2D CAD program and my favorite 3D CADCAM program to create assemblies with python.

It's easy to alter the design of the parts in this assembly by simply changing them in the dxf files:

Then re run the python script in HeeksPython:

One major improvement that I would like to do is to make the dxf_to_heekspython script deal with layers. Then I could do all the dxf editing in one file in Caduntu.
As I learn more about C++ programming, I might be able to utilize the functions in dxf.cpp from HeeksCAD itself. Importing would run much faster and I could take advantage of the things that already work well, like layers and importing polylines (which isn't currently implemented in the python script).

More DXF to HeeksPython Experiments

I created a python script to import a dxf file into HeeksPython, using parts of Doug Blanding's excellent python program 'Cadvas'. Doug and I have emailed back and forth over the years and he is happy to see his creation used for different things. He's not supporting it anymore, but in it's present state, it's a very good program to study. It's very simple and well laid out.
Included with Cadvas is the module. I have copied some of it and altered it to suite my needs for dxf to heekspython conversion and uploaded the script into the /examples directory in the HeeksPython project. This script is called Here are two profiles created in Qcad, that I want to manipulate in HeeksPython:

Here is a script to bring them into HeeksPython as separate revolved solid parts:

import HeeksPython as cad
import sys
import dxf_to_heekspython

units = 25.4 #inch units
part1 = "cad.setcolor(0,0,0)\n"
part1 = dxf_to_heekspython.gen_heekspython_entities(r1)
part1 = part1 +"cad.scale(sketch,0,0,0,units)\n"
part1 = part1 +"cad.setcolor(255,255,255)\n"
part1 = part1 +"cad.revolve(sketch,360)"
part2 = "cad.setcolor(0,0,0)\n"
part2 = dxf_to_heekspython.gen_heekspython_entities(r2)
part2 = part2 +"cad.scale(sketch,0,0,0,units)\n"
part2 = part2 +"cad.setcolor(0,255,0)\n"
part2 = part2 +"cad.revolve(sketch,360)\n"
part2 = part2 +"p1 = cad.getlastobj()\n"


Here is a screenshot of the resulting parts generated with this script:

The advantage of using this dxf_to_heekspython is that the dxf entities can be manipulated/transformed as they are brought in. I have some things that I would like to do with some dxf files - create solids by revolving them around the X axis. Eventually I will create cutaway views using this technique.

Friday, October 29, 2010

Well, it's been quite a long since I posted anything (obviously). I've been busy trying to learn a bit of C++ coding, in my quest to learn the ins and outs of HeeksCAD,HeeksCNC, and HeeksPython.
I am mostly doing the 'learn by example' route, plus a few good tutorials, books, and some very helpful advice from Dan Heeks himself. If I get into a bind, he usually can point to some example code that helps me understand things.
I have been able to add quite a few new functions to HeeksPython and a few things to HeeksCAD itself. HeeksPython is fun to add functions to, because there is a lot of 'low hanging fruit' so to speak. It's pretty easy to add a python binding to HeeksCAD, if there is already a C++ function in /interface/HeeksCADInterface.cpp . I started out by copying jonpry's existing functions ('NewArc', 'NewLine' etc). As I have gotten a little more experience, I have gotten more adventurous and added functions for deriving point data from the GraphicsCanvas itself. I also found a way of adding fillets to pairs of 2D lines. Over the last month, I have added ways of creating a new coordinate system,returning the parameters of coordinate systems,text,and a way of importing dxf files from python.
The HeeksPython function 'importdxf' is exiting for me because I have plans for creating solids quickly with the aid of other 2D cad programs like caduntu , qcad, or even true-type-tracer-dxf. Having HeeksPython loaded with functionality will help automate the design process somewhat.
Here is an example of a script that uses true-type-tracer-dxf to create some text on the HeeksCAD graphics screen:

import os
import HeeksPython as cad

path = '''/home/dan/Documents/drawings/ttt/'''
program = '''truetype-tracer-dxf'''
phrase = ''' \' this is a test \' '''
pipe = ''' > '''
file = '''aphrase.dxf'''

out = program + phrase + pipe + path + file

f = path + file


Sunday, July 4, 2010

HeeksCNC + python == APT360

One of my favorite CNC programming languages is APT360. It's a totally parametric way of creating gcode for cnc machines. It's also not very user friendly, if you don't use it all the time and get rusty, like I do. I'm a big fan of parametric programming and also a big fan of the python programming language. It's fairly easy for a non programming like me to get into and it's very popular, so there are many resources on the web for it.
In one of my previous blog entries, I mentioned that HeeksCNC uses python as the underlying scripting between the main C++ code and the post processed g-code. This week, Dan Heeks introduced a blank scipting object in HeeksCNC that lets the user create scripts in python and retain them in the order wanted in the HeeksCAD file. 'New Script Operation', as it's named in the HeeksCNC machining menu let's you do anything that you can think of in python and insert it into the Heeks python output.
As soon as I got my hands on the source code and compiled it, I started playing with parametric holes and helix operations.

Here is a small and very limited script for creating a helix in gcode:

def helix(x_cen,y_cen,z_depth,dia,pitch,z_clear):

    while (z_depth < z_clear):


        z_depth= z_depth+pitch


This snippet of code doesn't take into account anything having to do with tool radius/diameter.

Here you can see that I mixed script ops and a regular profile machining op:

Fun stuff!

Sunday, June 20, 2010

Drag and Drop in HeeksCAD

Yesterday, several of us were chatting with Dan Heeks on #cam in irc and someone asked him if he could add 'drag and drop' capabilities to HeeksCAD. This would make it much easier to put objects and operations in order for machining.
Dan went ahead and programmed this up today and it is great.
Now it is very easy to create sketches, copy them, and then paste them into different machining operations- and then put them in a logical machining order. It is also much easier to re-order sketches to one's own liking.

Now, it is very easy to reorder the sketches in the 'Objects' panel any way that you want.

Here's what I tried and was very pleased with:

I created a profile operation with one of the sketches.

I then copied all the other sketches and did a 'paste into' the profile operation

The order that the paths are machined isn't exactly optimized:

So then I dragged the sketches into the right order, inside the profile operation:

Here is what the paths look like now:

Similarly, you can do the same thing with machining operations like profile,pocket,drill,etc.

Saturday, June 5, 2010

Programming a Scanned Logo

I am doing a job for a guy who sent me a scanned bitmap of his logo. He wants this logo engraved on a brass guitar tailpiece.

I wanted to try out Inkscape to make an SVG file that I could import into HeeksCNC for generating Gcode. Inkscape has a 'trace bitmap' function under the 'Path' menu that should do the job. There are also some nice CNC gcode generating plugins for Inkscape that will make code directly out of the application. I prefer to use HeeksCNC for generating the code, because I have a good post processor for my Centroid controlled mill that lets me generate code without having to do any editing to it. I also need to combine some CAD data that don't trust to Inkscape with the logo, that's going to need to be engraved too.

The first thing that I did with that scanned image was open it in Gimp and crop it:

Then I imported it into Inkscape, made sure that it was still selected then did this:
1. In the top menu select 'Path'
2. select 'Trace Bitmap'

Here is the dialogue box that pops up (after I selected 'Brightness Cutoff' and 'Update'):

Once you hit 'OK' in that box, the converted vector path is hiding behind the original bitmap. I always slid it out from under the bitmap to look at it because I intended on copying and pasting the path into something else later.

If you copy and paste the vectorized path into a new Inkscape file, it can be saved as a new *.svg that Heekscad can import.

This looked pretty nice, but there was a problem- there were two paths all the way around the logo. I just want one nice clean path to engrave. Hmmm... it seems that the bitmap tracing looks at both edges of the black lines in the scan. I had played with 'Brightness Cutoff' and 'Edge detection' in the bitmap trace dialogue in Inkscape. 'Brightness Cutoff' seemed to give better results initially.
I opened up the bitmap in Gimp again and tried doing a bucket fill with black. This looked ok, but the original lines were actually lighter than the bucket fill. So, I darkened the lines up a bit and then did a bucket fill.

when I brought this back into Inkscape, I could do 'Edge detection' and get a reasonable path. It was still double paths, but they were much closer together.

I was then able to delete the outside path (that I thought I didn't really need) and create a much more reasonable toolpath.

Monday, May 31, 2010

Roughing and Sawing in the mill

I am making some brass parts on my mill that require some drilling, milling, and sawing with a jeweler's saw. I thought that this would be a good chance to try HeeksCNC out with these operations.
HeeksCNC has some very good operations for drilling and profiling that would be handy for this, but there is nothing in the way of automatic roughing or multi pass sawing. I ended up using some other CAD tricks and HeeksCNC's python scripting to make things work.
Here is the drawing as it imported into HeeksCAD:

The stair step shaped part is the thing that I am ultimately cutting out. On the right and left corners of it, I have added (in another CAD program) some roughing passes to cut the corners of my stock off:

The roughing actually looks like this on my Bridgeport mill:

I also needed to saw some slits in the sides of the part. I wanted to do the sawing with 4 passes of the saw blade on each side. I used my CAD program to offset the final saw path back half the diameter of the saw blade and then offset it 3 additional times by .050".

Obviously, it's critical not to retract the saw blade in the Z axes at the wrong time,and I wanted to keep the saw blade down at the right Z level while doing these passes, so I needed to do something to avoid using HeeksCNC's usual profiling method of doing a path, retracting in Z and then doing the next path. I resorted to some Python scripting tricks.
1. I selected the lines that I had drawn in CAD for sawing in HeeksCNC and generated a Profile operation with them. This allowed me to extract the geometric points that I needed.
2. I copied the python script from HeeksCNC and pasted it into my favorite text editor.
3. The script was easy to understand and manipulate- I just wanted a series of 'feed' and 'rapid' in the right spots.I didn't use any loops, because I was lazy....

Here is my sawing script:

comment('tool change to 2.755 saw')
tool_change( id=4)
feedrate_hv(15, 6)
clearance = float(0.5)
rapid_down_to_height = float(0.07874015748)
start_depth = float(0)
step_down = float(0.156)
final_depth = float(-0.156)
tool_diameter = float(2.755)

rapid(x=6.218827292, y=-1.060352717)

feed(x=6.076573626, y=-1.200936811, z=-0.156)
feed(x=4.101644628, y=0.7974459866, z=-0.156)

comment('Rapid Away')
rapid(x=4.266169148, y=0.9154947677)
rapid(x=6.218827292, y=-1.060352717)

feed(x=5.994311367, y=-1.25996122, z=-0.156)
feed(x=4.019382367, y=0.7384215961, z=-0.156)
comment('Rapid Away')
rapid(x=4.266169148, y=0.9154947677)
rapid(x=6.218827292, y=-1.060352717)

feed(x=5.912049106, y=-1.31898563, z=-0.156)
feed(x=3.937120107, y=0.6793972059, z=-0.156)

comment('Rapid Away')
rapid(x=4.266169148, y=0.9154947677)
rapid(x=6.218827292, y=-1.060352717)

feed(x=5.829786846, y=-1.37801, z=-0.156)
feed(x=3.854857847, y=0.6203728154, z=-0.156)
comment('Rapid Away')
rapid(x=4.266169148, y=0.9154947677)

rapid(x=-2.953405945, y=0.07385377598)

feed(x=-2.787292165, y=0.1930428677, z=-0.156)
feed(x=-1.668332953, y=-2.357971772, z=-0.156)

comment('rapid away')
rapid(x=-1.834446732, y=-2.477160866)
rapid(x=-2.953405945, y=0.07385377598)

feed(x=-2.704235276, y=0.2526374134, z=-0.156)
feed(x=-1.585276063, y=-2.298377244, z=-0.156)

comment('rapid away')
rapid(x=-1.834446732, y=-2.477160866)
rapid(x=-2.953405945, y=0.07385377598)

feed(x=-2.621178386, y=0.3122319591, z=-0.156)
feed(x=-1.502219173, y=-2.238782677, z=-0.156)

comment('rapid away')
rapid(x=-1.834446732, y=-2.477160866)
rapid(x=-2.953405945, y=0.07385377598)

feed(x=-2.538121535, y=0.3718265047, z=-0.156)
feed(x=-1.419162283, y=-2.17918815, z=-0.156)

comment('rapid away')
rapid(x=-1.834446732, y=-2.477160866)
rapid(x=-2.953405945, y=0.07385377598)


Here is what things looked like on the milling machine:

Friday, May 21, 2010

Engraving an award plaque

A friend of from Boy Scouts emailed me this week and asked if I could make an award plaque for her son to present this coming week. I've done plenty of plaques before, but mostly by using closed source software to generate the code. Today, I thought I would try out some of my favorite tools to get the job done-HeeksCNC,QCAD, and that can be found here:

-This code used to be located on fenn's server, but it seems to be down now. I just put a copy up on google to preserve it.

Anyway, to use this python script you need to edit a string inside the script itself (I know- that's not very user friendly, but that's the way it is for now). There are a few variables to play with and viola! you can run the script like this:

python > output_file_name.ngc

I created a border and 'fluer di le' in Qcad and imported it into HeeksCAD:

I opened up the output_file_name.ngc file in gedit and then pasted in the code created in HeeksCNC. Here it is in emc2/axis:

Here is a finished piece, mounted to a nice mahogany board:

Thursday, May 20, 2010

Running Python Scripts with the 'Program' Window

HeeksCNC has a unique feature that I really like: all operations create python code that gets processed to make G-code. In the 'Window' menu check the 'Program' option. While you are creating operations and G-code, look at what is happening in the 'Program' window.

You can manipulate the python code in the Program window to do all sorts of interesting things. I think that this feature in HeeksCNC gives it a lot of power, similar to APT360. I am very familiar with APT programming and like it a lot, but I really prefer python and the HeeksCNC approach.

The code from the Program window can be edited and used in the window itself. Simply edit the code and then press the 'Py+Go' (Run Python Script) button. Don't just press the 'Go' button, because it will populate the Program window with the normal python code that comes from the operations in HeeksCNC.

You can also copy and edit the python code in your favorite text editor, if you like. I do that because it's what I am familiar with.

The python code can also be run in a stand alone mode- outside of HeeksCNC, if you are careful to fix up any path problems. I sometimes run the python scripts this way, if I have my geometry set and just want to try different variables out with the code, ie different depths of cut.

One simple thing that you can do with the code is to use an operation over and over again with different size tool diameters or different depths. 'if' or 'while' loops make this sort of thing pretty easy to deal with.
In the next screen shot, I took the module and copied/edited it and saved it as (I commented out #rapid(z = mat_depth + incremental_rapid_height) on line 229). I simply wanted to keep the tool down in the work for my next trick:

Here is my python code that I pasted into the Program window:

import sys
import math
import kurve
import rough_funcs
from import *
import nc.centroid1

program_begin(123, 'Test program')

#(1/8 inch HSS Centre Drill Bit)
tool_defn( id=1, name='1/8 inch HSS Centre Drill Bit', radius=0.0625, length=0.94)
#(3/16 inch HSS Drill Bit)
tool_defn( id=2, name='3/16 inch HSS Drill Bit', radius=0.09375, length=5)
#(#31 HSS Drill Bit)
tool_defn( id=3, name='#31 HSS Drill Bit', radius=0.06, length=5)
#(#28 HSS Drill Bit)
tool_defn( id=4, name='#28 HSS Drill Bit', radius=0.07, length=0.7)
#(1/8 inch HSS End Mill)
tool_defn( id=5, name='1/8 inch HSS End Mill', radius=0.0625, length=2.5)
#(1/16 inch Carbide End Mill)
tool_defn( id=6, name='1/16 inch Carbide End Mill', radius=0.03125, length=0.3125)
#(#21 HSS Drill Bit)
tool_defn( id=7, name='#21 HSS Drill Bit', radius=0.0795, length=5)
#(engraving cutter)
tool_defn( id=20, name='engraving cutter', radius=0.0625, length=0.625)
comment('tool change to 1/8 inch HSS End Mill')
tool_change( id=5)
feedrate_hv(33.07086614, 3.937007874)
clearance = float(0.1968503937)
rapid_down_to_height = float(0.07874015748)
start_depth = float(0)
step_down = float(0.25)
final_depth = float(-0.25)
roll_on = 'auto'
roll_off = 'auto'
tag = None

roll_radius = float(0)
offset_extra = 0
k1 =
kurve.add_point(k1, 0, -1.732283465, -0.7086614173, 0.0, 0.0)
kurve.add_point(k1, 0, 0.157480315, 0.9448818898, 0.0, 0.0)
kurve.add_point(k1, -1, 0.4724409449, 1.062992126, 0.4718257874, 0.5856299213)
kurve.add_point(k1, 0, 1.417322835, 1.102362205, 0.0, 0.0)
kurve.add_point(k1, -1, 1.732283465, 0.9448818898, 1.432465172, 0.7389460933)
kurve.add_point(k1, 0, 2.125984252, 0.07874015748, 0.0, 0.0)

k2 =
kurve.add_point(k2, 0, 2.125984252, 0.07874015748, 0.0, 0.0)
kurve.add_point(k2, 0, 1.732283465, 0.9448818898, 0.0, 0.0)
kurve.add_point(k2, 1, 1.417322835, 1.102362205, 1.432465172, 0.7389460933)
kurve.add_point(k2, 0, 0.4724409449, 1.062992126, 0.0, 0.0)
kurve.add_point(k2, 1, 0.157480315, 0.9448818898, 0.4718257874, 0.5856299213)
kurve.add_point(k2, 0, -1.732283465, -0.7086614173, 0.0, 0.0)

tool_diameter = float(0.75)
rough_funcs.profile(k1, 'right', tool_diameter/2, offset_extra, roll_radius, roll_on, roll_off, tag, rapid_down_to_height, start_depth, step_down, final_depth)

tool_diameter = float(0.625)
rough_funcs.profile(k2, 'left', tool_diameter/2, offset_extra, roll_radius, roll_on, roll_off, tag, rapid_down_to_height, start_depth, step_down, final_depth)

tool_diameter = float(0.5)
rough_funcs.profile(k1, 'right', tool_diameter/2, offset_extra, roll_radius, roll_on, roll_off, tag, rapid_down_to_height, start_depth, step_down, final_depth)

tool_diameter = float(0.375)
rough_funcs.profile(k2, 'left', tool_diameter/2, offset_extra, roll_radius, roll_on, roll_off, tag, rapid_down_to_height, start_depth, step_down, final_depth)

tool_diameter = float(0.25)
rough_funcs.profile(k1, 'right', tool_diameter/2, offset_extra, roll_radius, roll_on, roll_off, tag, rapid_down_to_height, start_depth, step_down, final_depth)

tool_diameter = float(0.125)
rough_funcs.profile(k2, 'left', tool_diameter/2, offset_extra, roll_radius, roll_on, roll_off, tag, rapid_down_to_height, start_depth, step_down, final_depth)

rapid(z = clearance)


Sunday, May 16, 2010

Tooltable in HeeksCNC

HeeksCNC has a nice tooltable feature in the Objects Tree.

You can edit the tools and export the tooltable and later re import it. I set up a default tool table named 'default.tooltable' that loads every time I open HeeksCNC.

This tooltable corresponds to the tools that I actually have loaded in my milling machine (or the values for the height offsets I have stored in it, since I don't have an automatic tool changer).

Here is my tool changing 'carousel':

Sunday, May 9, 2010

importing into HeeksCAD

Qcad drawings import into HeeksCAD with no problems. In the 'Objects' panel in the upper left area, you can see that all the layers are listed. If you click on one of the layers, you will see some of it's properties and can choose to make it not visible. This is handy for working on a CNC program with HeeksCNC.

sketching and importing

I'm using Qcad to do all the sketching on my latest project. I have gotten used to how Qcad works and it's not too bad. One thing that I haven't figured out is if Qcad can import other files. So far, I don't think that it can.

Saturday, May 8, 2010

HeeksCNC Postprocessing

I've been working with HeeksCNC over the last few weeks on a project that I'm going to mill out of brass. Since I have a Centroid M40 control on my CNC milling machine, I need a proper postprocessor for it. On Friday, I created one and did some editing to Dan Heeks' iso_modal post. Now I think I have things the way that I want them.
Anyone interested can look at the files here:
Look at, and machines.txt to see what I did.

Sunday, March 28, 2010

Here is the url for a project that I have really gotten into over the last year:

This project is really separated into a series of smaller bits that can all be put together to make a total open source CADCAM solution. HeeksCAD is the main engine for all the other libs. You can add these other libs to make it do more:

HeeksCNC- is the main plugin to make profiling gcode

once you install HeeksCAD and then get HeeksCNC set up as a plugin, then you can add more libs for doing pocketing, adaptive roughing, and surfacing in 3D:

libarea (pocketing):

libactp (adaptive roughing of pockets- high speed roughing):

opencamlib (Ander's Wallen's 3D surfacing libraries):

HeeksPython- let's you do some parametric design work in python

HeeksArt- this let's you do some Blender like editing of surfaces

I think the genius of Dan Heek's approach was making it easy to add libraries to his main program.

The main thing that one needs to get started is to have the Opencascade libraries set up on your system. These libraries seem to be a gift from the geometry gods that let developers get up to speed with professional CAD programs fast.
I've been working with HeeksCAD lately. Dan Heeks has created a very impressive open source CADCAM platform.
You can get the sources or binaries here: