[PythonCAD] Fwd: new Perl module CAD::Drawing

Eric Wilhelm ewilhelm at sbcglobal.net
Wed Sep 24 15:53:14 EDT 2003

I'm posting this to several mailing lists to gather interest from developers 
(I'd love to have your help), Perl users (testing appreciated) and cad users 
which might want to become Perl users (more Perl users always welcome.)

Reply or ignore as desired:)

For those not familiar with Perl, realize that this is simply a module 
(library) which acts as a back-end for your Perl scripts:

-----start code-----
use CAD::Drawing;  # makes the functions available
$drw = CAD::Drawing->new; # creates a "blessed" reference
$drw->addline( [ [ $x0, $y0], [$x1, $y1] ], $layer, $color, $linetype);
# selection methods allow you to grab things by layer, type, and property:
@redcircles = $drw->getAddrByColor("some layer", "circles", "red");
# with manipulation methods for groups and single bits:
$drw->GroupRotate( 35 . "d", $xc, $yc, {"addrlist" => [@redcircles]});
# this will rotate all of the red circles about $xc,$yc 
# at an angle of 35 degrees (radians by default (thus the "d"))
$childpid = $drw->save("newfile.dwg", {"dofork" => 1});	
# that lets it fork and child exit on completed save
# this won't fork (e.g. won't continue to ps until done saving the dxf.)
$drw->save("thumbnail.png", {"width" => 200, "height" => 150} );
$drw->save("print_this.ps", {"show border" => 1, "noclone" => 1});
# the noclone option is just for memory savings 
# (you wouldn't normally do this unless it were the last save operation)
-----end code-----

There is a lot going on in this small chunk of code and this module is still 
fairly young, but is getting really powerful.  Notice the single point of 
interface to any supported file format.  The save functions have some 
automatic assumptions built into them (such as scale-to-fit for finite 
formats like images and postscript) but the design is such that there are 
options to over-ride these defaults (or at least some place where support for 
the options could be written into the code.)

I've tried to keep the mnemonic load down by allowing english names or color 
numbers, and other such niceties (with preliminary support for translation 
between Image::Magick and acad color space (and eventually Image::Magick 
english color names.))

I'm hoping that it will be interface stable really soon (need to change some 
of the list-based function calls to hash-reference based to support a wider 
range of options (or something (maybe apply the options via a second-step to 
the same object (which would eliminate some of the drawn-out options hashes 
that could result.))))  Not to mention the nested parentheses and brackets 
and such.

I'd appreciate comments from potential users and developers.  

See below for newsgroup post reference and places where help would be useful.

I'll be working on getting this to a released state (hopefully fairly soon.)

Items not mentioned in the newsgroup post that I would also like to pursue:

1. getting gpl-compatible dwg support via Art's dwg.py (as a wrapper or 
2.  (briefly touched on) Dime library dxf/dwf support.  Anybody worked with 
this before?
3.  (briefly touched on) Inline.pm version of the OpenDWG library wrapper.
4.  iges, step, and brep support via openCascade?
5.  use of this module as the basis for a test-bed and proof-of-concept for 
linking associative and parametric data into single-entity-based databases 
(filesystem (e.g. xspace and Draft) or sql (soon underway with PostgreSQL and 
simple point&line exchange with Catia (via excel and vba?)))

If you would like to help with the development, testing, or distribution, 
contact me off-list, on-list, via the newsgroup or whatever.  I could really 
use some makefile help and some suggestions on how to get the whole thing 
packaged into a readily installable form.

I'd also love to have help with supporting other formats and improving the 
dwg/dxf access (the entire toolset has evolved from an 
originally-non-object-oriented module built from a swig wrapper of the 
opendwg toolkit and could use some re-vamping.)  I've managed to hack my way 
through the C code, but I'm not very experienced at that, so C/perlguts help 
would be really great.


Posted today on comp.lang.perl.modules
<pan.2003. at somethinglike.sbcglobalDOTnet>

----------  Forwarded Message:  ----------

I've constructed a fairly extensive object oriented 2D geometry
manipulation module which is currently capable of reading and writing dwg
and dxf formats via the OpenDWG consortium's toolkit.  It also currently
supports saving to postscript or Image::Magick raster formats without any
additional effort besides 
	$drw->save("file.jpg", \%options); 
	$drw->save("file.ps", \%options);

Manipulation methods include move, copy, rotate, scale (and soon mirror.)

It is approaching interface stability, and has support for most 2D
elements (point, line, polygon, circle, arc, text, and images.)  Layers
and colors are well supported, but linetypes are hard:(  Some entities
are only partially supported, some things are missing such as text 
formatting details and images (which are read-only.)  Points and lines
are usable as 3D elements, but not well supported by the manipulations
(though I have been careful to not lose the z-coordinate when it is

The entire toolset consists of several files, which are all currently
declared as "package Drawing", with the exception of the DWG wrapper
(package DWG.)

I plan to re-arrange all of the package names to CAD::Drawing in a tree
such as this:

|-- Drawing
|   |-- Calculate.pm
|   |-- Defined.pm
|   |-- Dime.pm
|   |-- Finite.pm
|   |-- Manipulate.pm
|   `-- OpenDWG.pm
`-- Drawing.pm

	Defined.pm contains exports, but is intended only for back-end use

	Dime.pm does not exist yet (but would give GNU compatible 
	access to dxf files)

	OpenDWG.pm would have to be an optional xs module due to the
	consortium's licensing (free to use, not to distribute)

	files under Drawing/ would have "package Drawing" declarations

More information about the PythonCAD mailing list