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 dxf.py 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 dxf_to_heekspython.py. 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
sys.path.insert(0,'/home/dan/heeks/heekspython2/examples')
import dxf_to_heekspython
units = 25.4 #inch units
cad.setcolor(255,255,255)
r1='/home/dan/Documents/drawings/revolve1.dxf'
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)"
exec(part1)
cad.setcolor(0,255,0)
r2='/home/dan/Documents/drawings/revolve2.dxf'
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"
exec(part2)
cad.view_extents()
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.
No comments:
Post a Comment