[PythonCAD] To adapt LISP routine to Pythoncad

Art Haas ahaas at airmail.net
Thu May 24 03:02:08 CEST 2007

On Wed, May 23, 2007 at 02:17:51PM -0300, Tecg? S?rgio A. Bizello wrote:
> Hi !

> Wich is the Pythoncad programming language if I want to create
> something as a script or other commands sequence for work's routine?

Python is your best bet. :-)

> How I load Pythoncad commands inside this "automation" ? 

If I'm understanding you correctly, you want to work on your scripts
while running PythonCAD, and then loading them into your active session
so you can use them. I think you can do this right now by typing
something like  ...


... in the entry box at the bottom of the screen, but I've not tried
this lately so it may not work.

> For example, how can I create a script that draw a line between
> two specific points or rotate an existing object ?

You can do both of those tasks right now through the interface. If you
are trying to make actions like this into scriptable actions you'll
need to figure out what steps you want the user to follow for your
script to get the needed parameters.

Creating a Segment from two points is essentially the following:

def add_set(p1, p2)
   lp1 = p1.getParent()
   lp2 = p2.getParent()
   if lp1 is not None and lp2 is not None and lp1 is lp2:
      seg = segment.Segment(p1, p2)

In the example we test that both the parent layer of 'p1' and 'p2'
are the same (and not None) and, if so, make a new segment and add
it into the layer. You can expand this by doing things like adjusting
the color, linetype, and line style if you want. As for rotating
objects, look in 'PythonCAD/Generic/rotate.py' for how things currently

> How can I adapt a LISP routine from AutoCAD to PythonCAD ?

That would be a neat trick. Right now I don't know, and PythonCAD
currently can't parse AutoLisp routines. There would need to be
some sort of lisp parser added to the PythonCAD code for something
like this to work.

> Can I create dialogue boxes ?

Yes. Look at various files in 'PythonCAD/Interface/Gtk' for bits
of code making 'gtk.Dialog' objects.

> Thank you.

You're welcome.

Art Haas
Man once surrendering his reason, has no remaining guard against absurdities
the most monstrous, and like a ship without rudder, is the sport of every wind.

-Thomas Jefferson to James Smith, 1822

More information about the PythonCAD mailing list