Nate Holt's Blog

February 12, 2011

Programmatically adding active dwg to active project – AutoCAD Electrical

Filed under: Electrical — nateholt @ 10:55 am

One line of Lisp code is all it takes for your custom application to add the active drawing to the current active AutoCAD Electrical project.

This question came up a couple days ago… “How can I program my custom application to take each drawing it creates and automatically add it to the current AutoCAD Electrical project?” You could do this the hard way by opening up the active project’s “.wdp” text file and add the full path to the new drawing to the end of that file.

But there’s a cleaner way that is used in the Spreadsheet –> PLC I/O utility to add each new PLC I/O drawing to the active project. This AutoCAD Electrical command is run from “full source code” mode and it is written in AutoLISP. So, maybe we can just take a look at this source code, find the right spot, and cut/paste a block of code into our custom application ( ! )

Finding the source file: wdio.lsp

Start AutoCAD Electrical. Type this at your AutoCAD command prompt:  

Command:  (findfile “wdio.lsp”)  [Enter]

It should return the full path to the PLC I/O utility’s source file. If this fails, try this one:  (c:ace_find_file “wdio.lsp” 3) [Enter]. Make backup copy of this file (just in case)

Open the “wdio.lsp” file

Use any ASCII text editor or type VLIDE [Enter] at the AutoCAD command prompt and use the built-in Visual Lisp editor.

Scroll down. The key part of the file that saves the active dwg to the current active project is excerpted below:

      (setq x (c:wd_is_cur_dwg_in_proj))
        ((> x 0)) ; this drawing is already listed in the project
        ((< x 0)) ; no project is marked as "active" ??
        ((= x 0) ; active dwg is not listed in active project, add it now.
          ; Call the normal AutoCAD Electrical "API" call for updating active drawing's title block
          ;    First sublist (of 13 elements, 1 for selected, 0 for not selected )
          ;    1st =  mapped to DWGDESC (the description under drawing "properties")
          ;    2nd = mapped to DWGSEC
          ;    3rd = mapped to DWGSUB
          ;    4th = mapped to FILENAME
          ;    5th = mapped to FILENAMEEXT
          ;    6th = mapped to FULLFILENAME
          ;    7th = mapped to DWGNAM
          ;    8th = mapped to SHEET
          ;    9th = mapped to SHEETMAX
          ;   10th =
          ;   11th = mapped to IEC_P (the drawing's IEC coding default for %P)
          ;   12th = mapped to IEC_I (the drawing's IEC coding default for %I)
          ;   13th = mapped to IEC_L (the drawing's IEC coding default for %L)
          (c:wd_tb_process_one 1 (list (list 1 1 1 1 1 1 1 1 0 0 1 1 1))) ; update title block
          (c:ace_add_dwg_to_project nil (list "" "" "" 1)) ; first "nil" = add active dwg
      ) )

The key command that pushes the active dwg into the active project is highlighted in red above. If you know that the active drawing is not in the active project, executing just this one-line AutoLISP expression should push the drawing into the project.

Note: here’s a quick test… just type at the command prompt and hit [Enter]…


Command: (c:ace_add_dwg_to_project nil (list “” “” “” 1))

Checking files for any marked in-use/read-only . . .




… and the drawing appears in the project manager of active project.


About these ads

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Shocking Blue Green Theme. Blog at


Get every new post delivered to your Inbox.

Join 32 other followers

%d bloggers like this: