Take a look here
Registered forum members do not see this ad.
I was wondering if someone might be able to help me.
I'm trying to use the leader command within a few simple lisp routines. I'm having trouble with the leader finishing (text input), before the next command takes effect. The next command is being used as text or canceling the leader.
It's been many years since I've played with lisp, and with all the new stuff in 2005, I'm a little lost. I would think there is some way to isolate the leader action then continue.
An example would be to:
1. gather current layer settings.
2. draw leader with custom arrowhead & input desired text.
3. change back to orignal layer (or begin other commands).
Also, can someone list some good books on Autolisp that I can get locally?
Thanks,
Steve



Take a look here
Here are some sample code to look at.
The leader command can be tricky. I don't use ACAD2005, yet.
Code:(defun Leader_Mk (/ lpts pt1 pt2) (setq pt1 (getpoint "\nStart point: ")) (setvar "OSMODE" 0) (setq pt2 (getpoint pt1 "\nTo point: ")) (setq lpts (list pt2 pt1)) (command ".PLINE" pt1 pt2) ; command is still active ;; CONTINUE GETTING SUCCESIVE POINTS UNTIL STOP (while (setq pt1 (getpoint pt2 "\nTo point: ")) (command pt1) ; extend pline (setq lpts (cons pt1 lpts) pt2 pt1 ) ) ; while (command "") ; end pline (entdel (entlast)) ; remove the pline ;; create a leader in it's place (command "LEADER") (foreach pt1 (reverse lpts) (command pt1) ) (command "" "" "N") ; end leader (chglayer "DIMENSION") ;;============================== ;; remainder of your code ;;============================== ); defunCode:; Ldr.lsp (c) 2001 Tim Wilson ; Similar to the Quick Leader but without the text prompts (defun c:lk (/ lpt1 lpt2 lpt3) (setq #OSM (getvar "osmode")) (setq #OTM (getvar "orthomode")) (setq #CLE (getvar "clayer")) (setvar "OSMODE" 0) (setvar "orthomode" 0) (IF (NULL (tblsearch "layer" "Text")) (command "layer" "m" "Text" "c" "2" "" "") (command "layer" "s" "Text" "" "") );end if (setq lpt1 (getpoint "\nPick Start Point..: ")) (setq lpt2 (getpoint lpt1 "\nPick Next Point..: ")) (setvar "ORTHOMODE" 1) (setq lpt3 (getpoint lpt2 "\nPick End Point..: ")) (if (null lpt3) (command "leader" lpt1 lpt2 "a" "" "n") (command "leader" lpt1 lpt2 lpt3 "a" "" "n") );end if (setvar "osmode" #osm) (setvar "orthomode" #otm) (setvar "clayer" #CLE) (princ) );end defun (PRINC)Code:;;;================================================================ ;;; Insert text with 3 point leader ;;;================================================================ (defun c:leader_block (/ blkname xscale ang p1 p2 p3 dist ofdistr ofdistr) (setq blkname "MyBlock" xscale 1 ang 0 ofdistr 2 ; offset distance from leader to right ofdistl -16 ; offset distance from leader to left ) (setvar "orthomode" 0) (if (setq p1 (getpoint "\nPick start point of leader." ) ) (if (setq p2 (getpoint p1 "\nPick next point of leader.")) (progn (command ".line" p1 p2 "") (setvar "orthomode" 1) (setq p3 (getpoint p2 "\nPick end of leader.")) (entdel (entlast)) ; delete line ;; create leader only (command ".qleader" p1 p2 p3 ^c ^c) ;; offset dist from end of leader 2 units (setq dist (if (<= (car p2) (car p3)) ofdistr ; right hand leader ofdistl ; left hand leader ) ) (command "-insert" blkname ; block name (polar p3 0 dist) ; insertion point xscale ; x scale "" ; y scale, use xScale ang ; rotation angle ) ) ) ) )Code:(defun c:label_prop (/ usercmd useros userormode entl ent lname pt pt2 pt3 offset ofsdir txtjust dwg_ht laytag lname ) ;; LAYERTRANSVALUES returns an assoc list in ;; the format: (object_layer label text_layer) (defun layertransvalues () ;; Tag Replacement ' (("EX_" "Existing") ("EX-" "Existing") ;; add to list when needed ;; Tag MUST be in upper case ) ) ;; ================================ (setq usercmd (getvar "CMDECHO")) (setvar "CMDECHO" 0) (setq useros (getvar "osmode")) (setvar "osmode" 0) (setq userormode (getvar "osmode")) (setvar "orthomode" 0) (if (setq ent (entsel "\Select an entity to label.")) (progn (setq pt (cadr ent) lname (cdr (assoc 8 (entget (car ent)))) ;LAYER NAME offset 2 ; amount of box offset from text ) ;; Layer name check ============= (foreach laytag (layertransvalues) (if (and (= (strcase (substr lname 1 (strlen (car laytag)))) (car laytag) ) (> (strlen lname) (strlen (car laytag))) ) (setq lname (strcat (cadr laytag) " " (substr lname (1+ (strlen (car laytag)))) ) ) ) ) (setq cur_qleader (acet-ql-get)) ; Save current settings ;Set qleader default to framed text (acet-ql-set '((3 . "") (40 . 0.0) (60 . 0) (61 . 1) (62 . 1) (63 . 1) (64 . 0) (65 . 0) (66 . 0) (67 . 3) (68 . 0) (69 . 0) (70 . 0) (71 . 1) (72 . 1) (170 . 0) ) ) (if (setq pt2 (getpoint pt "\nPick Next Point..: ")) (progn (command "._line" pt pt2 "") (setq entl (entlast)) (setvar "ORTHOMODE" 1) (if (setq pt3 (getpoint pt2 "\nPick End Point..: ")) (command "._qleader" pt pt2 pt3 lname "") (command "._qleader" pt pt2 "" lname "") ) ;end if (entdel entl) ) ) (acet-ql-set cur_qleader); restore qleader defaults ) ) (setvar "CMDECHO" usercmd) (setvar "osmode" useros) (setvar "orthomode" userormode) (princ) ) ;;---------------------------------------------------------------------- ;; Qleader settings ;;---------------------------------------------------------------------- ;; See Frank Whaley's code for more options (defun acet-ql-get (/ xr cod itm reply) (if (setq xr (dictsearch (namedobjdict) "AcadDim")) (progn (foreach cod '(3 40 60 61 62 63 64 65 66 67 68 69 70 71 72 170 340) (if (setq itm (assoc cod xr)) (setq reply (append reply (list itm))) ) ) reply ) '((3 . "") (40 . 0.0) (60 . 0) (61 . 1) (62 . 1) (63 . 3) (64 . 0) (65 . 0) (66 . 0) (67 . 3) (68 . 1) (69 . 0) (70 . 0) (71 . 0) (72 . 0) (170 . 0)) ) ) (defun acet-ql-set (arg / cur prm) (setq cur (acet-ql-get)); fetch current ;; override per argument (while arg (setq prm (car arg) arg (cdr arg) cur (subst prm (assoc (car prm) cur) cur) ) ;; handle DIMLDRBLK (if (= 3 (car prm)) (setvar "DIMLDRBLK" (cdr prm)) ) ) ;; put back (dictremove (namedobjdict) "AcadDim") (setq cur (append '((0 . "XRECORD")(100 . "AcDbXrecord")(90 . 990106)) cur)) (dictadd (namedobjdict) "AcadDim" (entmakex cur)) (acet-ql-get) )
Hi again,
I'm here before you exhausted and frustrated. I'm posting this as I positive that way more people have WAY more experience than myself at this autolisp...er...stuff.![]()
Thank you everyone for the codes...however, I'm afraid I'm a little ignorant of the substance of the code. I'm curious as to why you need to draw a PLine then replace it with a leader.
Below is what I have so far, along with the indicated trouble spot. It could be that I'm way off on the ability of what I want to accomplish, but here is the code. If indeed, it's not possible, please let me know so I can stop beating a dead ox.
I really would like to change back to the original layer as when we draw the conduit or tag devices, we can just run the lisp to tag it then continue on drawing conduit.
Code:
(defun c:pnts (/ ol oc)
(setvar "cmdecho" 1)
(setq ol (getvar "Clayer") ;Original layer
oc (getvar "CECOLOR") ;Original color
pt1 (getpoint "Pick Leader Start Point... ") ;starting point as reference
)
(command "dimldrblk" "NONE") ;removes arrowhead
(command "layer" "m" "E-SERT-PNTS" "c" "red" "E-SERT-PNTS" "") ;creates, sets layer
(setvar "cecolor" "bylayer") ;sets color (if not already)
(command "_.leader" pt1 pause pause) ;begins leader command
;; This is where I have trouble. I can either have everything on the desired layer,
;; but NOT switch back at the end. Or the layers/color switch and then place the leader text.
;; Yes, I'm sure there are more involved lisp routines to draw leaders and place text.
;; But it just seems logical (maybe my mistake) to use all the functions of the built-in
;; leader command.
;; I would also like to use this same methodology to create cable callouts using a user-
;; supplied arrowhead.
(setvar "clayer" ol) ;returns to orig layer
(setvar "cecolor" oc) ;returns to orig color
(princ)
)
Thanks a bunch for all the help.
Steve




Hi Steve,
The problem is in the "leader" command; the number of pauses needs to excatly match the input. Where there is an indetrerminate number of inputs to the command, the following code snippet should do the trick. HTH!
(command "_.leader" pt1) ;begins leader command
(while (> (getvar "CMDACTIVE") 0)
(command pause);;continues to pause for input until leader command is ended
)
Registered forum members do not see this ad.
SteveC
Did CarlB's answer fix your problem?
Bookmarks