Author Topic: Reverse Layers  (Read 6304 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
Reverse Layers
« on: February 05, 2008, 11:17:17 AM »
Does anyone have a copy of a lisp which can reverse layers so that frozen layers thaw, thawed layers freeze, on to off locked to unlocked etc etc.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Reverse Layers
« Reply #1 on: February 05, 2008, 11:32:12 AM »
You can modify this one.
Note that the current layer must be changed.
Code: [Select]
  ;;  Toggle Layer On/Off -  CAB 091404 
  (defun layt (/ doc lname)
   (vl-load-com) ; load ActiveX support
   (setq doc (vla-get-activedocument (vlax-get-acad-object)))
                         
   (vlax-for for-item (vla-get-layers doc);(vla-GetExtensionDictionary)
     (setq lname (vlax-get-property for-item 'Name))
     (if (eq :vlax-true
             (vlax-get-property(vla-item (vla-get-Layers doc ) lname)'LayerOn))
        (vlax-put-property (vla-item (vla-get-Layers doc) lname)
          'LayerOn :vlax-false); layer OFF
        (vlax-put-property (vla-item (vla-get-Layers doc) lname)
          'LayerOn :vlax-true); layer ON
     ); endif
   ); vlax-for
  ); defun
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.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Reverse Layers
« Reply #2 on: February 05, 2008, 12:06:24 PM »
Hi,

If you want to reverse the 3 properties (lock, freeze and on) at the same time (note: current Layer wont be frozen)

Code: [Select]
(vlax-for l (vla-get-Layers
      (vla-get-ActiveDocument (vlax-get-acad-object))
    )
  (foreach p '(Lock Freeze LayerOn)
    (if (= (vlax-get l p) -1)
      (vlax-put l p 0)
      (vl-catch-all-apply 'vlax-put (list l p -1))
    )
  )
)
Speaking English as a French Frog

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Reverse Layers
« Reply #3 on: February 05, 2008, 12:12:32 PM »
Here is one I use for on/off layers.  It allows you to select layers that are off to turn them on.

It can propably be modified for the other possibilities


Code: [Select]
;;; ------------------------------------------------------------------------
;;;    LLO.LSP Version 1.0
;;;
;;;    Copyright© MAY, 2001
;;;    Timothy G. Spangler
;;;
;;;    Permission to use, copy, modify, and distribute this software
;;;    for any purpose and without fee is hereby granted, provided
;;;    that the above copyright notice appears in all copies and
;;;    that both that copyright notice and the limited warranty and
;;;    restricted rights notice below appear in all supporting
;;;    documentation.
;;;
;;;    Allows the user to turn on selected layers
;;;
;;; ------------------------------------------------------------------------
(defun C:LLO (/ Off Layer EntList LayerName LayerList Color)

;; Create lists o on/off layers
(while (setq Layer (tblnext "LAYER" (null Layer)))
(if (minusp (cdr (assoc 62 Layer)))
(setq Off T)
)
)
;; Select layers to turn on
(if Off
(progn
;; Invert layers
(while (setq Layer (tblnext "LAYER" (null Layer)))
(LAYER_SWITCH (cdr (assoc 2 Layer)))
)
;; Select layers to turn on
(while (setq EntName (car (entsel "\n Select layers(s) to turn on:")))
(setq EntList (entget EntName))
(setq LayerName (cdr(assoc 8 EntList)))
(setq LayerList (entget (tblobjname "LAYER" LayerName)))
(setq Color (assoc 62 LayerList))
(entmod (subst (cons 62 (- (cdr Color))) Color LayerList))
)
;; Reinvert layers
(while (setq Layer (tblnext "LAYER" (null Layer)))
(LAYER_SWITCH (cdr (assoc 2 Layer)))
)
)
(princ "\n All layers are turned on")
)
(princ)
)
;; Sub routine to turn layers on/off
(defun LAYER_SWITCH (Layer / Tmp Clr)

(setq Tmp (entget (tblobjname "LAYER" Layer)))
(setq Clr (assoc 62 Tmp))
(entmod (subst (cons 62 (- (cdr Clr))) Clr Tmp))
(princ)
)
;;;
;;; Echos to the command line
(princ "\nTurns on selected layers v1.0 \n ©Timothy Spangler, \n May, 2001....loaded.")
(terpri)
(princ "C:LLO")
(print)
;;; End echo
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Reverse Layers
« Reply #4 on: February 05, 2008, 12:26:03 PM »
Nice one Gile. :-)
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.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Reverse Layers
« Reply #5 on: February 05, 2008, 12:33:03 PM »
Speaking English as a French Frog

JohnK

  • Administrator
  • Seagull
  • Posts: 10604
Re: Reverse Layers
« Reply #6 on: February 06, 2008, 09:15:05 AM »
On a lighter side, you can always just flip the bits.

Here is a real quick stab (You can have the job of making it pretty).

Code: [Select]
( (lambda ( layername / layer lsylst props off freeze lock )

    ;; 70 - Standard flags (bit-coded values):
    ;; 1  = Layer is frozen; otherwise layer is thawed
    ;; ...
    ;; 4  = Layer is locked
    ;; ...
    ;; 62 - Color number (if negative, layer is off)

    (setq layer (tblobjname "LAYER" layername))
    (setq laylst (entget layer)
          props (cdr (assoc 70 laylst))
          off (cdr (assoc 62 laylst))
          freeze 1
          lock 4
          )

    (setq props (boole 6 props freeze))
    (setq off (1+ (~ off)))
    (setq props (boole 6 props lock))

    (setq laylst (subst (cons 70 props) (assoc 70 laylst) laylst)
          laylst (subst (cons 62 off) (assoc 62 laylst) laylst))

    (entmod laylst)
    )
 "<YOUR LAYER NAME HERE>"
 )

Oh, and just be careful with this lil baby ( HINT: current layer).
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10604
Re: Reverse Layers
« Reply #7 on: February 06, 2008, 09:29:32 AM »
Oh and just in case some one decides to be cute; i know 1+4=5. I choose the longer route so i didn't just post a two line obscure-ish procedure.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Reverse Layers
« Reply #8 on: February 06, 2008, 10:13:52 AM »
Interesting John, always thinking outside the box!   8-)
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.

daron

  • Guest
Re: Reverse Layers
« Reply #9 on: February 06, 2008, 11:02:11 AM »
>Oh, and just be careful with this lil baby ( HINT: current layer).
I ran your function John, with 0 as the current layer and it froze the current layer. However, it's a bit more of a trick to thaw it. Fun fun.

JohnK

  • Administrator
  • Seagull
  • Posts: 10604
Re: Reverse Layers
« Reply #10 on: February 06, 2008, 11:04:47 AM »
Interesting John, always thinking outside the box!   8-)

yeah, just saw the post yesterday before i shutdown for the night and was thinking about it when i drove in this morn. I thought it would be a fun little exercise.

But i suppose i cant take all the credit, SMadsen and i had a discussion about bit codes (OSMODE and such) once or twice where he demonstrated to me the power of a quick little bit flipper procedure.  Good fun stuff.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10604
Re: Reverse Layers
« Reply #11 on: February 06, 2008, 11:06:45 AM »
>Oh, and just be careful with this lil baby ( HINT: current layer).
I ran your function John, with 0 as the current layer and it froze the current layer. However, it's a bit more of a trick to thaw it. Fun fun.

Cool huh?
Just re-run the code

Now for my next trick i will delete layer zero in one of your production drawings.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

daron

  • Guest
Re: Reverse Layers
« Reply #12 on: February 06, 2008, 11:08:31 AM »
Just flip the bits again. That's what I figured and did, thanks. Interesting how you can't just go to the pull-down and thaw it though. At least it didn't work when I tried it.

daron

  • Guest
Re: Reverse Layers
« Reply #13 on: February 06, 2008, 11:09:18 AM »
That would be awesome. Ooh, better yet, Defpoints. Make that baby go away.

JohnK

  • Administrator
  • Seagull
  • Posts: 10604
Re: Reverse Layers
« Reply #14 on: February 06, 2008, 11:21:47 AM »
You cant thaw it via the Pull down or layer mgr cause your not supposed to be able to have the current layer frozen.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org