Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

layertoggle routine fails

3 REPLIES 3
Reply
Message 1 of 4
kdispoto
343 Views, 3 Replies

layertoggle routine fails

The routine below worked in Autocad 2008 in both model & paper space now in Autocad 2010 I get the following error when I try it in paperspace.. any ideas?

 

Command:
Command:
Command: ai_molc
** Command only valid in Model space **

 

 

;;;   Routine turns off all layers except the current layer and
;;;   any others you select.

;;;   Layers are reset next time lisp is called.

;;;   ...............................................
;;;   Adapted from Cadalyst TIP1350.LSP:   LYRTGL.LSP

 

;;;%%%%%%%%-MAIN FUNCTION-%%%%%%%%

(defun C:LYRTGL ( / SSET LYR LYR_LST1 LYR_NAME N INDEX GROUP_CODES)
  (graphscr)
  (setq #XECHO   (getvar "cmdecho")
        #XEXPERT (getvar "expert")
        *error*  lyrtgl_restore
  )
  (setvar "expert" 1)
  (setvar "cmdecho" 0)

  (if (not #LYR_LST2)
    (progn
      (prompt
"\nSelect entities on layers you want to remain on... or \nPress return for the current layer only."
      )
      (setq SSET      (ssget)
            LYR       (tblnext "layer" T)
            LYR_LST1  (getvar "clayer")
            #LYR_LST2 ""
      )
      (while LYR
        (if (< (cdr (assoc 62 LYR)) 0)
          (setq LYR_NAME  (cdr (assoc 2 LYR))
                #LYR_LST2 (strcat #LYR_LST2 "," LYR_NAME)
          )
        )
        (setq LYR (tblnext "layer"))
      )
      (if SSET
        (progn
          (setq N     (sslength SSET)
                INDEX 0
          )
          (repeat N
            (setq GROUP_CODES (entget (ssname SSET INDEX))
                  LYR_NAME    (cdr (assoc 8 GROUP_CODES))
                  LYR_LST1    (strcat LYR_LST1 "," LYR_NAME)
                  INDEX       (+ INDEX 1)
            )
          )
        )
      )
      (command ".layer" "off" "*" "on" LYR_LST1 "")
      (lyrtgl_restore "")
    )
    (progn
      (setq LYR      (tblnext "layer" T)
            LYR_LST1 ""
      )
      (while LYR
        (if (> (cdr (assoc 62 LYR)) -1)
          (progn
            (setq LYR_NAME (cdr (assoc 2 LYR))
                  LYR_LST1 (strcat LYR_NAME "," LYR_LST1)
            )
          )
        )
        (setq LYR (tblnext "layer"))
      )
      (command ".layer" "on" "*" "off" #LYR_LST2 "on" LYR_LST1 "")
      (setq #LYR_LST2 nil)
      (lyrtgl_restore "")
    )
  )
)
(defun lyrtgl_restore (S)
  (setvar "cmdecho" #XECHO)
  (setvar "expert" #XEXPERT)
  (setq #XECHO   nil
        #XEXPERT nil
  )
  (prompt (strcat "\n" S "\n"))
)
(princ "Type Lyrtgl to start. \nThe current layer will always remain on.")
(princ)

3 REPLIES 3
Message 2 of 4
andrew.nao
in reply to: kdispoto

this works for me

using 2010

 

if it doesnt work for you

you can try this, its pretty similar to what you posted

 

 

(defun c:matchoff (/ x )
   (setq x (entsel "\nSelect object whose layer is to be matched: "))
   (command "layer" "S" (cdr (assoc 8 (entget (car x)))) "" )

(PROMPT "\n\n\nSELECT OBJECTS TO TURN OFF THEIR ASSOCIATED LAYER!\n\n")
(SETVAR "CMDECHO" 0)
(SETQ SSA (SSGET))
(SETQ CNTA 0)
(SETQ STLY "")
(WHILE (SETQ EN (SSNAME SSA CNTA))
(SETQ ED (ENTGET EN))
(SETQ LY (CDR (ASSOC 8 ED)))
(SETQ LAY (GETVAR "CLAYER"))
(SETQ STYL (STRCAT "~*." LY ".*"))
(IF (AND (/= STLY "") (/= LY LAY) (WCMATCH STLY STYL)) (PROGN
(SETQ STY (STRCAT STLY "," LY))
(SETQ STLY STY)
)
)
(IF (AND (= STLY "") (/= LY LAY) (WCMATCH STLY STYL)) (PROGN
(SETQ STLY LY)
)
)
(IF (= LY LAY) (PROGN
(PROMPT (STRCAT "\n****<<<" LY ">>> IS THE CURRENT LAYER!!!***"))
)
)
(SETQ CNTA (1+ CNTA))
)
(COMMAND "LAYER" "OFF" STLY "")
(PROMPT (STRCAT "\nLAYER -<<" STLY ">>- IS OFF!"))
(PRINC)
)

Message 3 of 4
kdispoto
in reply to: kdispoto

Just found out that the error was on my end - for some reason I was calling ai_molc in the toolbar macro. All better now. Thanks

Message 4 of 4
andrew.nao
in reply to: kdispoto

well if you want ot just turn off selected layers you can also you the OOTB command

"_layoff"

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost