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…).