Jump to content

Recommended Posts

Posted

Hi All,

 

I am currently working on a LISP used to change the layer of certain entities in a drawing.

 

The LISP searches each layer in turn for TEXT entities, displays the results to the user, who then decides whether to proceed or move onto the next layer.

 

My question is related to an improvement for this LISP - is there any way to retrieve a list of all the Layers contained in a drawing?

 

We work to a template, and it is the layers in this template that I am currently using in my LISP - however, sometimes drawings will use other layers created by users editing the drawing.

 

I obviously don't want to have to edit my LISP for every drawing opened, and so any help would be greatly appreciated as always. :)

 

Here is the LISP that I am working on - if anyone finds it of any use, feel free to use it and modify it to suit your needs. :)

 

; Txtlay, created by Lee McDonnell October 2008

(defun c:txtlay (/ laylist ss ans)
   (setvar "cmdecho" 0)
   (setq laylist '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9" 
           "BORDER" "Defpoints" "DIM" "SIGNATURE")
   ) ; end setq

   ; for each Layer in laylist
   (foreach n laylist
       (if 
           (setq ss (ssget "X" 
                   (list 
                       (cons 0 "TEXT")
                       (cons 410 (getvar "ctab"))
                       (cons 8 n)
                   ) ; end list
               ) ; end ssget
           ) ; end setq
           (progn
               (sssetfirst nil ss)
               (initget "Yes No")
               (setq ans (getkword "Change Selected Entities to Text Layer? [Yes/No] <Yes> :" ))
               (if
                   (/= ans "No")
                   (progn
                       (command "_.chprop"
                           ss ""
                           "LA"
                           "TEXT"
                           "C"
                           "bylayer"
                           ""
                       ) ; end property change
                   ) ; end progn
               ) ; end if
           ) ; end progn
       ) ; end if
   ) ; end foreach
   (setvar "cmdecho" 1)
   (prompt "\nFunction Complete.")
   (princ)
) ; end program

Posted

hi lee mac, here's for looping layers:

 

  (setq layer (tblnext "LAYER" T))
 (while layer
   (princ (strcat "\nLayer name: " (cdr (assoc 2 layer))))
      (setq layer (tblnext "LAYER"))
 )

Posted

Hi Lee Mac. This is ActiveX example (do not foget (vl-load-com) once per AutoCAD session):

 

(defun GetLayerList(/ oLst)
 (vlax-for l (vla-get-Layers
       (vla-get-ActiveDocument
        (vlax-get-acad-object)))
   (setq oLst(cons(vla-get-Name l)oLst))
   ); end vlax-for
 (reverse oLst)
 ); end of GetLayerList

Posted

Thanks guys,

 

The Active X method works well ASMI - I really need to learn Active X methods - they seem to be able to do a lot more than the standard LISP functions.

 

I am working from an AutoLISP reference from R.11, and so this manual doesn't have Active X functions included - I will have to do a bit of research and learn about them. :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...