TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: A_LOTA_NOTA on March 21, 2011, 10:56:48 AM

Title: label xref layer
Post by: A_LOTA_NOTA on March 21, 2011, 10:56:48 AM
I can't think of a time I have ever needed something like this but a coworker asked for it. Someone had already done most of the code I just tried to make it work with xrefs also. I like to post things here to see how others would do it. Normally I find it could be done with a lot less code.

So here it is...

Code: [Select]
(defun c:LABEL (/ culay lead clay omode a a1 ent entl txt position pt1 pt2)
  (setvar "CMDECHO" 0)
  (setq culay (getvar "users1"))
  (setq lead (getvar "users2"))
  (setq clay (getvar "clayer")) 
  (setq omode (getvar "osmode"))
  (prompt (strcat "\nEnter Layer for label:" "<" culay ">")) 
  (setq a (getstring))
  (setq a1 (if (= a "") culay a))
  (setvar "users1" a1)
  (setvar "clayer" a1)
  (setvar "osmode" 0)
  (command "._mspace") 
  (cond
    ((setq ent (entsel))
     (setq entl (entget (car ent)))
     (and (= "INSERT" (cdr (assoc 0 entl))) (setq ient (nentselp (cadr ent))) (setq entl (entget (car ient))))
     (setq txt (cdr (assoc 8 entl)))
     (if (setq position (vl-string-position (ascii "|") txt))
       (setq txt (substr txt (+ position 2)))
       ); end if
     (command "._pspace")
     (command "._dim1" "_l" (getpoint "\nEnter Leader Start Point: ") (getpoint "\nEnter Possition For label: ") "" txt)
     )
    ) ; end cond
  (setvar "osmode" omode)
  (setvar "clayer" clay)
  (setvar "CMDECHO" 1)
  (princ)
  ); end defun
Title: Re: label xref layer
Post by: Matt__W on March 21, 2011, 10:57:53 AM
You spelled "POSITION" wrong.   :wink: