+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    SteveC
    Guest

    Default Using leader in lisp

    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

  2. #2
    Super Member
    Using
    Architectural DT 2007
    Join Date
    Dec 2002
    Location
    London
    Posts
    1,087

    Default

    Take a look here

  3. #3
    Super Member CAB's Avatar
    Using
    AutoCAD 2000
    Join Date
    May 2004
    Location
    Tampa, Florida
    Posts
    801

    Default

    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
      ;;==============================
    ); defun
    Code:
    ; 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
    	&#40;setq dist &#40;if &#40;<= &#40;car p2&#41; &#40;car p3&#41;&#41;
    		     ofdistr ; right hand leader
    		     ofdistl ; left hand leader
    		   &#41;
    	&#41;
    
    	&#40;command "-insert"
    		 blkname           ; block name
    		 &#40;polar p3 0 dist&#41; ; insertion point
    		 xscale            ; x scale
    		 ""                ; y scale, use xScale
    		 ang               ; rotation angle
    	&#41;
          &#41;
        &#41;
      &#41;
    &#41;
    Code:
    &#40;defun c&#58;label_prop &#40;/        usercmd  useros   userormode  entl    ent
                         lname    pt       pt2   pt3   offset   ofsdir   txtjust
                         dwg_ht   laytag   lname
                        &#41;
      ;; LAYERTRANSVALUES returns an assoc list in 
      ;; the format&#58; &#40;object_layer label text_layer&#41; 
      &#40;defun layertransvalues &#40;&#41;
        ;;  Tag  Replacement
        '
         &#40;&#40;"EX_" "Existing"&#41;
          &#40;"EX-" "Existing"&#41;
          ;; add to list when needed
          ;;  Tag MUST be in upper case
         &#41;
      &#41;
      ;;  ================================
      &#40;setq usercmd &#40;getvar "CMDECHO"&#41;&#41;
      &#40;setvar "CMDECHO" 0&#41;
      &#40;setq useros &#40;getvar "osmode"&#41;&#41;
      &#40;setvar "osmode" 0&#41;
      &#40;setq userormode &#40;getvar "osmode"&#41;&#41;
      &#40;setvar "orthomode" 0&#41;
      &#40;if &#40;setq ent &#40;entsel "\Select an entity to label."&#41;&#41;
        &#40;progn
          &#40;setq pt     &#40;cadr ent&#41;
                lname  &#40;cdr &#40;assoc 8 &#40;entget &#40;car ent&#41;&#41;&#41;&#41; ;LAYER NAME
                offset 2 ; amount of box offset from text
          &#41;
          ;;  Layer name check  =============
          &#40;foreach laytag &#40;layertransvalues&#41;
            &#40;if &#40;and &#40;= &#40;strcase &#40;substr lname 1 &#40;strlen &#40;car laytag&#41;&#41;&#41;&#41;
                        &#40;car laytag&#41;
                     &#41;
                     &#40;> &#40;strlen lname&#41; &#40;strlen &#40;car laytag&#41;&#41;&#41;
                &#41;
              &#40;setq lname &#40;strcat &#40;cadr laytag&#41;
                                  " "
                                  &#40;substr lname &#40;1+ &#40;strlen &#40;car laytag&#41;&#41;&#41;&#41;
                          &#41;
              &#41;
            &#41;
          &#41;
    
          &#40;setq cur_qleader &#40;acet-ql-get&#41;&#41; ; Save current settings
          ;Set qleader default to framed text
          &#40;acet-ql-set '&#40;&#40;3 . ""&#41; &#40;40 . 0.0&#41; &#40;60 . 0&#41; &#40;61 . 1&#41;
                         &#40;62 . 1&#41; &#40;63 . 1&#41;   &#40;64 . 0&#41; &#40;65 . 0&#41;
                         &#40;66 . 0&#41; &#40;67 . 3&#41;   &#40;68 . 0&#41; &#40;69 . 0&#41;
                         &#40;70 . 0&#41; &#40;71 . 1&#41;   &#40;72 . 1&#41; &#40;170 . 0&#41; &#41;
          &#41;
          &#40;if &#40;setq pt2 &#40;getpoint pt "\nPick Next Point..&#58; "&#41;&#41;
            &#40;progn
              &#40;command "._line" pt pt2 ""&#41;
              &#40;setq entl &#40;entlast&#41;&#41;
              &#40;setvar "ORTHOMODE" 1&#41;
              &#40;if &#40;setq pt3 &#40;getpoint pt2 "\nPick End Point..&#58; "&#41;&#41;
                &#40;command "._qleader" pt pt2 pt3 lname ""&#41;
                &#40;command "._qleader" pt pt2 "" lname ""&#41;
              &#41; ;end if
              &#40;entdel entl&#41;
            &#41;
          &#41;
          &#40;acet-ql-set cur_qleader&#41;; restore qleader defaults
        &#41;
      &#41;
      &#40;setvar "CMDECHO" usercmd&#41;
      &#40;setvar "osmode" useros&#41;
      &#40;setvar "orthomode" userormode&#41;
    
      &#40;princ&#41;
    &#41;
    ;;----------------------------------------------------------------------
    ;;             Qleader settings
    ;;----------------------------------------------------------------------
    ;;  See Frank Whaley's code for more options
    &#40;defun acet-ql-get &#40;/ xr cod itm reply&#41;
      &#40;if &#40;setq xr &#40;dictsearch &#40;namedobjdict&#41; "AcadDim"&#41;&#41;
        &#40;progn
          &#40;foreach cod '&#40;3 40 60 61 62 63 64 65 66 67 68 69 70 71 72 170 340&#41;
            &#40;if &#40;setq itm &#40;assoc cod xr&#41;&#41;
              &#40;setq reply &#40;append reply &#40;list itm&#41;&#41;&#41;
            &#41;
          &#41;
          reply
        &#41;
        '&#40;&#40;3 . ""&#41; &#40;40 . 0.0&#41; &#40;60 . 0&#41; &#40;61 . 1&#41;
          &#40;62 . 1&#41; &#40;63 . 3&#41;   &#40;64 . 0&#41; &#40;65 . 0&#41;
          &#40;66 . 0&#41; &#40;67 . 3&#41;   &#40;68 . 1&#41; &#40;69 . 0&#41;
          &#40;70 . 0&#41; &#40;71 . 0&#41;   &#40;72 . 0&#41; &#40;170 . 0&#41;&#41;
      &#41;
    &#41;
    
    &#40;defun acet-ql-set &#40;arg / cur prm&#41;
      &#40;setq cur &#40;acet-ql-get&#41;&#41;;  fetch current
      ;;  override per argument
      &#40;while arg
        &#40;setq prm &#40;car arg&#41;
              arg &#40;cdr arg&#41;
              cur &#40;subst prm &#40;assoc &#40;car prm&#41; cur&#41; cur&#41; &#41;
        ;;  handle DIMLDRBLK
        &#40;if &#40;= 3 &#40;car prm&#41;&#41;
          &#40;setvar "DIMLDRBLK" &#40;cdr prm&#41;&#41; &#41;
      &#41;
      ;;  put back
      &#40;dictremove &#40;namedobjdict&#41; "AcadDim"&#41;
      &#40;setq cur &#40;append '&#40;&#40;0 . "XRECORD"&#41;&#40;100 . "AcDbXrecord"&#41;&#40;90 . 990106&#41;&#41; cur&#41;&#41;
      &#40;dictadd &#40;namedobjdict&#41; "AcadDim" &#40;entmakex cur&#41;&#41;
      &#40;acet-ql-get&#41;
    &#41;

  4. #4
    SteveC
    Guest

    Default I give up...

    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

  5. #5
    Forum Deity
    Using
    not specified
    Join Date
    Jul 2004
    Location
    Anchorage, Alaska
    Posts
    2,074

    Default

    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
    )

  6. #6
    Super Member CAB's Avatar
    Using
    AutoCAD 2000
    Join Date
    May 2004
    Location
    Tampa, Florida
    Posts
    801

    Default

    Registered forum members do not see this ad.

    SteveC
    Did CarlB's answer fix your problem?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts