Author Topic: Multiple layer isolate  (Read 5045 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 3942
  • C3D user & customizer
Re: Multiple layer isolate
« Reply #15 on: March 17, 2006, 02:50:38 PM »
Try this....if the current layer gets turned off then the first object's layer will become current.
Code: [Select]
(defun c:LayIso (/ ss idx ent lay lays)
  (prompt "\nSelect objects on layer to Isolate: ")
  (if (setq ss (ssget))
    (progn
      (setq echo (getvar "cmdecho"))
      (setvar "cmdecho" 0)
      (setq idx -1)
      (while (setq ent (ssname ss (setq idx (1+ idx))))
(setq lay (cdr (assoc 8 (entget ent))))
(if (not (member lay lays))
  (setq lays (cons lay lays))
  )
)
      (if lays
(progn
  (command "undo" "be")
  (command ".layer" "off" "*" "y" "")
  (mapcar '(lambda (x)
     (command ".layer" "on" x "")
     )
  lays)
  (command ".layer" "s" (last lays) "")
  (command "undo" "end")
  )
)
      (setvar "cmdecho" echo)
      )
    )
  (princ)
  )

TJAM51

  • Guest
Re: Multiple layer isolate
« Reply #16 on: March 17, 2006, 03:04:42 PM »
It works...thanks bunches :-D

CAB

  • Global Moderator
  • Seagull
  • Posts: 10362
Re: Multiple layer isolate
« Reply #17 on: March 17, 2006, 03:18:09 PM »
Not to happy with the code but here is one that will freeze all but selected layers
The selected layers are turned off temporally as you select them.

Code: [Select]
;;  CAB 08.21.08  [ Limited Testing ]  version 3
;;  User pick of layers to remain Thawed, freeze all others
;;  Picked layers turn off as picked, when Enter is pressed
;;  picked layers are thawed & turned on and all others are frozen
;;
;;  modified to allow current layer to be frozen, makes the first
;;  thawed layer current
;;
;;  If a layer in an xref is selected the layer the xref is on can
;;  not be frozen
;;
;;  Layer 0 in an xref will not be frozen
;;
;;  added uiso to restore the previous layer states
;;
(defun c:liso (/ laylst thalst ent lname xrlays)
 (vl-load-com)
  ;; get current layer settings
  (defun getlayerdata (doc / lst)
    (vlax-for layObj (vla-get-layers doc)
      (setq lst (cons (list layObj
                            (vla-get-freeze layObj)
                            (vla-get-layeron layObj)
                      )
                      lst)))
    lst
  )

  (defun xrefp (ent / elist blist)
    (and
      (setq elist (entget ent))
      (setq blist (entget (tblobjname "BLOCK" (cdr (assoc 2 elist)))))
      (= 4 (logand (cdr (assoc 70 blist)) 4))
    )
  )

  (defun LayerOff (layname doc) ; added for version 3
    (vla-put-LayerOn (vla-item (vla-get-layers doc) layname) :vlax-false)
  )

  (command ".undo" "begin")
  (setq *laysts (getlayerdata (vla-get-activedocument (vlax-get-acad-object)))
        *clayer (getvar "clayer")
  )

  (prompt "\nLayers picked will turn off during selection.")
  (while (setq ent (nentsel "\nPick layers to keep thawed. Enter when done"))
    (setq lname (cdr (assoc 8 (entget (car ent)))))
    (if (vl-position lname xrlays)
      (prompt "\nFlagged xref layer can not be frozen.")
      (if (and (= lname "0") (cadddr ent) (xrefp (last (nth 3 ent))))
        (prompt "\nLayer 0 in xref can not be frozen.")
        (progn
        (setq thalst (cons lname thalst))
        (LayerOff lname (vla-get-activedocument (vlax-get-acad-object)))
        (if (and (cadddr ent) (xrefp (car (nth 3 ent))))
          (progn    ; save the xref layer
            (setq xrlays (cons (cdr (assoc 8 (entget (last (nth 3 ent))))) xrlays)
                  thalst (cons (car xrlays) thalst)
            )
          )
        )
        )
      )
    )
  )
  (if thalst
    (progn
      (setq laylst (list (cdr (assoc 2 (tblnext "layer" t))))
            clayer (getvar "clayer")
      )
      (while (setq lay (cdr (assoc 2 (tblnext "layer"))))
        (if (and lay
                 (not (member lay thalst))
                 (/= lay clayer)
            )
          (setq laylst (cons lay laylst))
        )
      )
      (if (vl-position *clayer laylst)
        (setvar "clayer" (car thalst))
      )
      (command "._Layer")
      (mapcar '(lambda (x) (command "_f" x)) laylst)
      (command "")
      (command "._Layer")
      (mapcar '(lambda (x) (command "_ON" x)) thalst)
      (command "")
    )
  )
  (command ".undo" "end")
  (princ)
)
(prompt "\n*-*  Layers Isolate loaded, Enter LayISO to run.  *-*")
(princ)



;;  restore previous layer settings
(defun c:uiso (/ doc)
  (setq doc    (vla-get-activedocument (vlax-get-acad-object))
        clayer (vla-get-activelayer doc)
  )
  (if *laysts
    (progn
      (vlax-for layObj (vla-get-layers doc)
        (if (and (setq lyrdat (assoc layObj *laysts))
                 (not (equal clayer layObj))
            )
          (progn
            (vla-put-freeze layObj (cadr lyrdat))
            (vla-put-layeron layObj (caddr lyrdat))
            (if (= *clayer (vla-get-name layObj))
              (vla-put-activelayer doc layObj)
            )
          )
        )
      )
      (setq lyrdat (assoc clayer *laysts))
      (if (/= *clayer (vla-get-name (car lyrdat)))
        (vla-put-freeze (car lyrdat) (cadr lyrdat))
      )
      (vla-put-layeron (car lyrdat) (caddr lyrdat))
      (vla-regen doc acactiveviewport)
    )
  )
)

<edit: code updated>
« Last Edit: August 13, 2010, 12:55:01 PM by CAB »
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.