Nate Holt's Blog

August 2, 2010

Adding custom option to Insert WBlock Circuit command – AutoCAD Electrical

Filed under: Electrical — nateholt @ 12:03 am

Preserving pre-positioned wire number locations in the inserted circuit (i.e. bypassing AutoCAD Electrical’s auto wire number centering feature)

Developing a nice, custom application for auto drawing generation was being thwarted. The application would pop in various circuits into the overall drawing. Some of these circuits were set up with aliased wire numbers at pre-defined wire number locations designed to give a pleasing appearance.

But pushing these circuits into the drawing using AutoCAD Electrical API call “(c:wd_ins_circ2…)” was doing too much clean-up. It would see the existing wire numbers come in with the selected Wblocked circuit and try to “center” each on its wire segment.

The desired behavior is that AutoCAD Electrical do everything BUT re-center any existing wire numbers. I wanted the pre-positioned wire number positions to be held where I had defined them in the Wblocked circuit. So, in the example above, the original wire number positions as carried in the WBlocked circuit .dwg file would be where each full wire number would appear and would “stick”.

But there was no option for this API call to trigger the function to skip re-centering existing wire numbers. What to do???

Necessity is the Mother of Invention

That’s what my mother would sometimes quote to me growing up… when I asked for something that just didn’t seem to be available. And she learned it from her parents as she grew up during the Great Depression. Researching this a bit, looks like the originator was Plato. Guess this is one of those deja vu things.

Let’s see what we can come up with.

We turn on the AutoCAD Electrical “Trace mode” and then insert our circuit. You can manually turn this on by typing this at the “Command:” prompt: (setq Aw_Debug 1) [Enter]  (and turn it off by typing (setq Aw_Debug nil) [Enter]).

The command window gives a long, cryptic sequence of what internal calls AutoCAD Electrical makes as it inserts the circuit, reconnects wires, re-tags components and RE-CENTERS any existing wire numbers ( ! ).

Here is a screen shot of some of this output. A clue is highlighted…

So we give it a shot. We type this in at the command prompt:

(defun wd_wnum_calc_good_wnum_locs ( a / ) nil )

What this does is redefine this internal AutoCAD Electrical function for just the active drawing on-screen (this is because AutoCAD Electrical loads a copy of its executable into each drawing as it opens on screen). Our temporarily redefined function just returns nothing or “nil” when it is now called. We try the circuit insert and get a “wrong number of arguments” error. Let’s try again… maybe there are two arguments for this internal AcadE function…

(defun wd_wnum_calc_good_wnum_locs (a b / ) nil ) 

Bingo! It works!

Is this a good idea. Donno, but again… it seems to work.

Wrapping up our solution

Okay, let’s clean this idea up a bit. Let’s put a “wrapper” around the standard AutoCAD API call for inserting the WBlock circuit. But this wrapper will first save the existing version of the “(wd_wnum_calc_good_wnum_locs…)” function. Then it will redefine it to have it do nothing. Then we make the normal call to the “Insert WBlock Circuit” command. And we finish by restoring the original behavior of “(wd_wnum_calc_good_wnum_locs…)”.

Here’s what our wrapper around the standard API call might look like:

Now, whenever I want to insert a circuit but NOT have it auto re-center existing wire numbers, I make a call to (c:wd_ins_circ2x…) instead of the normal AcadE API version (c:wd_ins_circ2…).



  1. […] Add sounds to your too-quiet AutoLisp utility Updating drawings from scratch database edits Tutorial – Using Excel with AutoCAD Electrical (Part 4 – Wire numbers) Tutorial – Using Excel with AutoCAD Electrical (Part 3) Tutorial – Using Excel with AutoCAD Electrical (Part 2) Tutorial – Using Excel with AutoCAD Electrical (Part 1) Adding custom option to Insert WBlock Circuit command […]

    Pingback by Index of AutoCAD Electrical Utilities – April 2006 through August 2010 « AutoCAD Electrical Etcetera — September 1, 2010 @ 3:50 pm

  2. I was reviewing the method you presented for preserving pre-positioned wire number locations in the inserted circuit and was wondering if you thought it would be possible to have similar logic work for renumbering a complete project. The issue we have when renumbering a project is similar to the one when inserting a circuit. Time was taken when doing the original drawings to place the wire numbers in locations for a “pleasing appearance”, but once you auto renumber an entire project the location that was selected is lost and a new location is used for the wire numbers. We are using ACADE 2009 and will be upgrading to ACADE in a few months.

    Comment by Donna Shallow — November 9, 2010 @ 5:54 pm

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

Blog at

%d bloggers like this: