Author Topic: select an area and deactivate all layers, that are NOT in this selected area  (Read 1374 times)

0 Members and 1 Guest are viewing this topic.

vozer

  • Guest
Hey Guys!

I am looking for a possibility to select an area in the model space and deactivate all layers, that are NOT in this selected area.

Is there a a code to do this out there? Or would it be easy to generate based on an existing snippet?

Cheers
« Last Edit: December 19, 2016, 10:52:00 AM by vozer »

ChrisCarlson

  • Guest
I'm sure you'd be able to fashion something, each of these steps can be found on this board. 

Step 1 - Gather objects within a crossing or window selection
Step 2 - Add the layers of each object to a list
Step 3 - Remove duplicates
Step 4 - Process each item in the list
Step 5 - ...
Step 6 - ...
Step 7 - Profit

ChrisCarlson

  • Guest
or you simply use the built-in layer isolate command

Grrr1337

  • Swamp Rat
  • Posts: 812
I use this since.. (I was born LOL):

Always wondered who was the author, until digged into the code now:
Code: [Select]
;;  LayerIsolateThawFreezeThaw.lsp [command names: LIT, LUT]
;;  To Isolate/Unisolate Layers of selected objects as to Thaw/freeze condition only.
;;  LIT isolates Layers of selected objects, leaving those Layers thawed and freezing
;;  all other Layers that are not already frozen.  If repeated before LUT re-thaws those
;;  Layers, makes further isolations, to as many levels as desired.
;;  LUT thaws latest set of frozen Layers, without undoing other Layer options that
;;  may have been used under isolated conditions [as happens with some (e.g. colors)
;;  if using AutoCAD's standard LAYUNISO to return to un-isolated conditions after
;;  using LAYISO (as to On/Off status)].  When repeated, steps back through as many
;;  isolations as done with LIT, in reverse order [LAYUNISO can reverse only one].
;;  Kent Cooper, last edited 10 January 2014

; LIT - ISOLATES SELECTED LAYERS
; LUT - UNISOLATES ALL LAYERS

(vl-load-com)

(defun litV (sub); = build Variable name for (set): subtype + current integer ending
  (read (strcat "lit" sub (itoa litinc)))
); defun

(defun litG (sub); = Get what's in variable made by (set) and (litV)
  (eval (read (strcat "lit" sub (itoa litinc))))
); defun

(defun C:LIT (/ ss laysel layname lithlist layobj); = Layer Isolate, Thaw/freeze
  (prompt "\nTo designate Layer(s) to remain thawed,")
  (if (setq ss (ssget)); object selection
    (progn
      (setq litdoc (vla-get-activedocument (vlax-get-acad-object)))
      (vla-startundomark litdoc)
      (repeat (sslength ss); make list of Layer names to remain thawed
        (setq laysel (cdr (assoc 8 (entget (ssname ss 0))))); Layer name
        (if (not (member laysel lithlist)) (setq lithlist (cons laysel lithlist))); add if not already there
        (ssdel (ssname ss 0) ss)
      ); repeat
      (setq litinc (if litinc (1+ litinc) 1)); litinc is global; 1 for first time, etc.
      (if
        (set (litV "cur"); global variable(s) litcur1, litcur2, etc., but only:
          (if (not (member (getvar 'clayer) lithlist)); nil if current Layer kept thawed
            (vlax-ename->vla-object (tblobjname "layer" (getvar 'clayer)))
          ); if
        ); set
        (setvar 'clayer (nth 0 lithlist)); then -- make some selected object's Layer current
      ); if
      (while (setq layname (cdadr (tblnext "layer" (not layname)))); step through Layer names
        (if
          (and
            (not (member layname lithlist)); not among selected objects' Layers
            (= (logand 1 (cdr (assoc 70 (tblsearch "layer" layname)))) 0); currently thawed
          ); and
          (progn ; then
            (setq layobj (vlax-ename->vla-object (tblobjname "layer" layname)))
            (set (litV "frz") (cons layobj (litG "frz")))
              ; put in list of frozen Layers -- makes global variables litfrz1, litfrz2, etc.
            (vla-put-freeze layobj 1); freeze it
          ); progn
        ); if
      ); while
      (prompt
        (strcat
          "\n"
          (itoa (length lithlist))
          " Layer(s) isolated, "
          (itoa (length (litG "frz")))
          " Layer(s) frozen."
          (if (litG "cur")
            (strcat "  Layer " (getvar 'clayer) " has been made current."); then
            "" ; else -- add nothing to prompt if current Layer remains thawed
          ); if
        ); strcat
      ); prompt
      (vla-endundomark litdoc)
    ); progn
    (prompt "\nNothing selected.")
  ); if
  (princ)
); defun

(defun C:LUT (/ lutgone lutcur); = Layer Unisolate, Thaw-freeze
  (if (> litinc 0); at least one list of frozen Layers exists
    (progn ; then
      (vla-startundomark litdoc)
      (foreach lay (litG "frz"); latest numbered list of frozen Layers as VLA objects
        (if (vlax-vla-object->ename lay); still in drawing
          (vla-put-freeze lay 0); then -- thaw it
          (progn ; else
            (vl-remove lay (litG "frz")); to adjust number for prompt later
            (setq lutgone (if lutgone (1+ lutgone) 1))
              ; quantity of no-longer-present Layers that were frozen by LIT
          ); progn
        ); if
      ); foreach
      (if ; restore Layer current at time of corresponding LIT if it was frozen
        (and
          (litG "cur"); nil if it wasn't
          (vlax-vla-object->ename (litG "cur")); Layer still in drawing, even if renamed
        ); and
        (progn
          (setq lutcur (vla-get-Name (litG "cur"))); name [if renamed since its LIT, new]
          (setvar 'clayer lutcur); restore as current
        ); progn
      ); if
      (prompt
        (strcat
          "\n"
          (itoa (length (litG "frz")))
          " Layer(s) re-thawed."
          (if (litG "cur"); corresponding LIT froze current Layer at the time
            (strcat ; then
              "\nLayer "
              (cond
                (lutcur); saved above only if still in drawing -- name, even if renamed
                ("current at time of LIT purged, and not")
              ); if
              " restored as current."
            ); strcat
            "" ; else -- add nothing if corresponding LIT kept current Layer thawed
          ); if
          (if lutgone (strcat "\n" (itoa lutgone) " purged Layer(s) not re-thawed.") "")
        ); strcat
      ); prompt
      (set (litV "frz") nil); clear list ending with latest integer in use
      (set (litV "cur") nil); clear current-at-LIT-Layer-if-changed value with latest integer
      (setq litinc (1- litinc)); increment downward for next-earlier list
      (terpri)
      (vla-regen litdoc 1); make things on re-thawed Layer(s) visible
      (vla-endundomark litdoc)
    ); progn
    (prompt "\nNo Layers to Unisolate."); else
  ); if
  (princ)
); defun

(prompt "\nType LIT to Isolate Layers [Thaw/freeze status only], LUT to Unisolate.")
I don't know if Kent Cooper is member of theswamp, but I'm thankful for this routine!  :smitten:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

vozer

  • Guest
Hey!

@master Shake: Thanks for the roadmap, i just read up about it and it seems pretty straight forward. I will jump into it after Christmas to learn something!

@Grrr1337:
Wow, thanks a lot! This is pretty much what i searched for! Would be nice to also be able to tell him to forget the rememberd thawing to make it permament, but this will have to do for now!