This issue has come up recently... user wants to insert a standard circuit
and have the tags on the devices and terminals all carry a common,
incrementing suffix value for each insertion of the circuit (ex: motor
circuit). Here is a quick example of how this might be implemented:
1. Construct your standard circuit ".dwg" file with "fixed" tags ending in
character "%". This character will serve as the place holder for the common
suffix value passed to the insert circuit command. So you might have fixed
tag "M%" on the motor symbol, "MS%" on the motor starter coil and on child
contacts (child contacts would not have to be "fixed"), terminal numbers
"A%", "B%"... on the various terminal symbols (not "fixed"), and so on.
2. Put a simple AutoLISP "wrapper" around the AcadE "INS CIRC" API call. A
possible approach is shown below. Then, instead of launching the normal
AcadE INS CIRCUIT command when you want to pop in a series of these
incrementing circuits, launch the "wrapper" program instead. It prompts you
for the "suffix" value and then proceeds to make it happen.
(defun c:ins_circ_increment ( / suffix val ed en #lastent #newlastent
newval)
(setq circ_to_insert nil)
(setq circ_insertion_xy nil)
(setq options 0) ; 1's bit set=keep fixed wire numbers
(setq suffix (getstring " SUFFIX value="))
(if (AND suffix (/= suffix ""))
(progn
(setq #lastent (entlast))
(c:wd_ins_circ2 circ_to_insert circ_insertion_xy 1.0 options)
(setq #newlastent (entlast))
(if (not (eq #lastent #newlastent))
(progn ; assume that circuit successfully inserted. Now process
; the inserted circuit. Look for block inserts.
(setq en #lastent)
(while (setq en (entnext en))
(progn
(setq ed (entget en))
(if (= (cdr (assoc 0 ed)) "INSERT")
(progn ; block insert found. Look for TAG1, TAG2, TAGSTRIP
attribute
(setq val (c:wd_getattrval en "TAG1,TAG1F,TAG2"))
(if (AND val (/= val ""))
(progn
; Check last character for target flag of "%"
(if (= (substr val (strlen val) 1) "%")
(progn ; Yes, make the substitution
(setq newval (strcat (substr val 1 (1- (strlen
val))) suffix))
(c:wd_modattrval en "TAG1,TAG1F,TAG2" newval nil)
) )
)
)
(if (c:wd_getattrval en "TAGSTRIP")
(progn ; hit a terminal
(setq val (c:wd_getattrval en "TERM*")) ; get terminal
number
; Check last character for target flag of "%"
(if (= (substr val (strlen val) 1) "%")
(progn ; Yes, make the substitution
(setq newval (strcat (substr val 1 (1- (strlen
val))) suffix))
(c:wd_modattrval en "TERM*" newval nil)
) )
) )
) ) ) )
) )
) )
(princ)
)