Wednesday, November 9, 2011

DraftSight and scripting

Generally, AutoCAD scripts (and hence DraftSight scripts, by association) have a bad reputation as a slow and clumsy alternative to LISP.  Okay, fine.  That's generally the case with any script language vs. a compiled or bytecode alternative.  The price is right; I'll live with it.

If you want to learn how to write DS scripts, the best place to learn is learn from the materials available for ACAD.  Search the Web for "Autocad script" or "Autocad script tutorial".  Almost all of what is written for ACAD applies to DS.

Remember that a lot of the commands that invoke a dialog box (like "LAYER") have a command-line-only, alternative version that begins with a hyphen or dash (like "-LAYER"), for use in scripts.  (Also for use by command-line geeks who don't like dialog boxes.  And Linux heads!  And Cygwin junkies!)

Since I haven't had a lot of practice with ACAD scripts myself, I expect to be doing a lot of fumbling around for the next little while.  One of my first tasks will be to find out how to pass arguments to a script, and how to have a script open a custom pop-up window, to prompt the user for a needed value.

Apparently, there's also a tiny macro language, called Diesel, with which ACAD users can modify the Status line and do other little tweaks.  It's been reported that Diesel macros work inside DS also.  One thing at a time, my friends.  I'm working on scripting this week.  But if you know something about Diesel, give it a shot and let me know what you find out.

By the way, the official AutoCAD user forums contain a few discussions about DraftSight.  

Some users were wondering about the legality of DS, considering that it's
so close to ACAD in functionality and features.  A little research into the Open Design Alliance and the IntelliCAD Technology Consortium would answer their questions - besides, I don't think that Dassault Systèmes would have put all that horsepower behind DraftSight if they didn't have all their ducks in a row, legally speaking.

Other users were dismissing DS as the latest in a long train of ACAD clones, none of which have been as good as real ACAD.  Well, they're absolutely right, without dispute.  It
is the latest, and it isn't quite as good as the real thing.  There's no question that AutoCAD deserves its place at the top of the heap.  If we could afford it, we would all use it, without a doubt.  But we can't, and so we look for compatible, lower priced alternatives, which will do most of what ACAD can do and all of what we need to get done.

I don't think that Autodesk or their customers have anything to fear from DS.  The ACAD installed base will continue to grow, contributing nicely to ACAD's bottom line, and although we all look forward to the DS installed base growing even faster, it will never overtake or replace ACAD.  I don't think that Dassault Systèmes intends it to do so, either.


Mike said...

Hi. This is my first blog post ever, so please forgive if this is the wrong forum for this. I use DraftSight to convert AutoCAD files to PDFs (as the first step in a several step file conversion). If I could have an external script to automatically run these DraftSight conversions, that would be fantastic. I would be willing to pay a developer to do this but don't know where to start. Can you help me understand if DraftSight can be used to do this and if so, what scripting language would be used? Even better, if you could point me perhaps toward a developer forum for this, I would be extremely grateful.

Zyzmog said...

@Mike, welcome to my blog. This should be a simple thing to do. Basically, you want to use a script to do three things: open the drawing in DraftSight, save the drawing as a PDF, and then close Draftsight. I'm not totally sure, but I believe that DS supports auto-start scripts, the kind that run when you open DS. It sounds like that would be ideal for your application. DS has a very rich scripting language, whose syntax matches the AutoCAD scripting language almost 100%.

You could also write a LISP program to do this for you. The advantage of Lisp is that it executes faster than a script. The two disadvantages are that LISP has a steeper learning curve than script, and the LISP capability costs money. It's not prohibitively expensive, though, and if you're going to be creating a lot more tools, then LISP might be the way to go. But try scripting first.

You can find a lot of online resources by searching for "autocad script tutorial." Almost anything that's written for or about ACAD works just fine with DS.

Zyzmog said...

p.s. to Mike: I'm just guessing here, but DS might also have the capability to run scripts in the background - that is, you never see DS open a window or anything while it's running your script.

Anonymous said...

I have a clumsy but effective solutions I employ. Using a ms-dos batch file to open every drawing in a folder and run a script to produce a PDF.

I do not have it available on this computer but I will put up some more details on Monday when I can.


Anonymous said...

please can you show that ms-dos batch file, how to open drawing together with added draftsight script and let it run