Author Topic: How to freeze a list of layers?  (Read 6178 times)

0 Members and 1 Guest are viewing this topic.

scottcd

  • Newt
  • Posts: 52
How to freeze a list of layers?
« on: September 30, 2008, 08:02:50 AM »
I have the following list of layers (filtered_layerlist)

("G8010001" "G8010004" "G8010010" "G8010015" "G8010021" "G8010026" "G8010027"
"G8010030" "G8010032" "G8010035" "G8010036" "G8010052" "G8010057" "G8010059"
"G8010071" "G8010072" "G8010098" "G8010321" "G8010374" "G8010376" "G8010382"
"G8010388" "G8010397" "G8010400" "G8010570" "G8010572" "G8011000" "G8011005"
"G8011006" "G8011009" "G8011010")

     I was trying to use the following to freeze all the layers in the above list

 (mapcar '(lambda (x) (command "layer" "freeze" x "") filtered_layerlist))

But I know the syntax is not correct for a start - can anyone give me a push in the right direction.

Cheers

Scott



AutoCAD Dos R9 - 2018 and BricCAD 18.2

kpblc

  • Bull Frog
  • Posts: 396
Re: How to freeze a list of layers?
« Reply #1 on: September 30, 2008, 08:26:58 AM »
Code: [Select]
(setq layers '("G8010001"      "G8010004"      "G8010010"      "G8010015"
               "G8010021"      "G8010026"      "G8010027"      "G8010030"
               "G8010032"      "G8010035"      "G8010036"      "G8010052"
               "G8010057"      "G8010059"      "G8010071"      "G8010072"
               "G8010098"      "G8010321"      "G8010374"      "G8010376"
               "G8010382"      "G8010388"      "G8010397"      "G8010400"
               "G8010570"      "G8010572"      "G8011000"      "G8011005"
               "G8011006"      "G8011009"      "G8011010"
               )
      ) ;_ end of setq

(defun test (lst / adoc)
  (vl-load-com)
  (vla-startundomark
    (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
    ) ;_ end of vla-StartUndoMark
  (foreach item lst
    (vl-catch-all-apply
      (function
        (lambda ()
          (vla-put-freeze (vla-item (vla-get-layers adoc) item) :vlax-true)
          ) ;_ end of lambda
        ) ;_ end of function
      ) ;_ end of vl-catch-all-apply
    ) ;_ end of foreach
  (vla-endundomark adoc)
  (princ)
  ) ;_ end of defun
Sorry for my English.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to freeze a list of layers?
« Reply #2 on: September 30, 2008, 08:42:54 AM »
If you're going to use the COMMAND, this will do.
Code: [Select]
(defun c:test()
 
(setq lst
       '("G8010001" "G8010004" "G8010010" "G8010015" "G8010021" "G8010026" "G8010027"
"G8010030" "G8010032" "G8010035" "G8010036" "G8010052" "G8010057" "G8010059"
"G8010071" "G8010072" "G8010098" "G8010321" "G8010374" "G8010376" "G8010382"
"G8010388" "G8010397" "G8010400" "G8010570" "G8010572" "G8011000" "G8011005"
"G8011006" "G8011009" "G8011010"))
  (setq str "")
  (mapcar '(lambda(x) (setq str (strcat str x ","))) lst)
  (command "_-layer" "_F" str "")
  (princ)
  )
Another version
Code: [Select]
(command "._Layer")
(mapcar '(lambda (x) (command "_f" x)) laylst)
(command "")
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.

scottcd

  • Newt
  • Posts: 52
Re: How to freeze a list of layers?
« Reply #3 on: September 30, 2008, 08:49:49 AM »
Thanks for both suggestions.  :-) :-)

Is there any reason to prefer one version over the other?

Cheers

Scott

AutoCAD Dos R9 - 2018 and BricCAD 18.2

scottcd

  • Newt
  • Posts: 52
Re: How to freeze a list of layers?
« Reply #4 on: September 30, 2008, 08:56:28 AM »
Thanks Cab,

I have used your second version - short and sweet!

I didn't know that you could put code in the middle of a command call like that :grazy:

Cheers
Scott

AutoCAD Dos R9 - 2018 and BricCAD 18.2

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to freeze a list of layers?
« Reply #5 on: September 30, 2008, 08:57:44 AM »
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to freeze a list of layers?
« Reply #6 on: September 30, 2008, 09:05:19 AM »
Thanks for both suggestions.  :-) :-)

Is there any reason to prefer one version over the other?

Cheers

Scott


The COMMAND version is often slower than the code version.
The COMMAND version may stop working with a different version of ACAD IF they change the
order of the prompts or the key word.
The COMMAND version is usually shorter code and easy for the novice to create.

Some programmers see the COMMAND version as SCRIPT writing and not real programing.  :-)
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.

GDF

  • Water Moccasin
  • Posts: 2081
Re: How to freeze a list of layers?
« Reply #7 on: September 30, 2008, 10:23:00 AM »
Thanks guys, I've learned something this morning.

I use the command version instead of a script now for controlling my layers in xrefs.

Code: [Select]
(defun c:1ST  (/ 1st str)
  (setq lst '("*DEF*" "*|A-ALT-WIND-2" "*|A-ALT-WIND-3" "*|A-AREA*" "*|A-CLNG*"
              "*|A-DOOR-CODE" "*|A-DIMS*" "*|JUNK" "*|A-NOTE*" "*|A-PATT*"
              "*A-SHTT*" "*|A-SYMB*" "*|LS*" "*|X-LINE*"))
  (setq str "")
  (mapcar '(lambda (x) (setq str (strcat str x ","))) lst)
  (command "_-layer" "_F" str "")
  (command "_-layer" "_T" "*|A-ALT-WIND-1" "")
  (princ))
(defun c:3RD  (/ 1st str)
  (setq lst '("*DEF*" "*|A-ALT-WIND-1" "*|A-ALT-WIND-3" "*|A-AREA*" "*|A-CLNG*"
              "*|A-DOOR-CODE" "*|A-DIMS*" "*|JUNK" "*|A-NOTE*" "*|A-PATT*"
              "*A-SHTT*" "*|A-SYMB*" "*|LS*" "*|X-LINE*"))
  (setq str "")
  (mapcar '(lambda (x) (setq str (strcat str x ","))) lst)
  (command "_-layer" "_F" str "")
  (command "_-layer" "_T" "*|A-ALT-WIND-2" "")
  (princ))

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

JohnK

  • Administrator
  • Seagull
  • Posts: 10657
Re: How to freeze a list of layers?
« Reply #8 on: September 30, 2008, 10:51:29 AM »
One more method:
http://www.theswamp.org/index.php?topic=690.msg16138#msg16138


CHA-CHING! ...That's where that code snip i had in my notes came from; i had my suspicions a bit of code i had in a file was from Stig, but now i have the proof.

Thanx CAB.

*[Se7en:] runs off to locate and comment code.*
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Andrea

  • Water Moccasin
  • Posts: 2372
Re: How to freeze a list of layers?
« Reply #9 on: September 30, 2008, 12:41:00 PM »
I think that You need to verify if the layer exist before..
and verify if you aren't to a layer who need to be freeze
You can not freeze current layer.

Code: [Select]
(setq layerlisttofreeze
       '("G8010001" "G8010004" "G8010010" "G8010015" "G8010021" "G8010026" "G8010027"
"G8010030" "G8010032" "G8010035" "G8010036" "G8010052" "G8010057" "G8010059"
"G8010071" "G8010072" "G8010098" "G8010321" "G8010374" "G8010376" "G8010382"
"G8010388" "G8010397" "G8010400" "G8010570" "G8010572" "G8011000" "G8011005"
"G8011006" "G8011009" "G8011010"))

(foreach l layerlisttofreeze
  (if (and
(not (eq (strcase (getvar "CLAYER")) (strcase l)))
(member (strcase l) (mapcar 'strcase (ai_table "LAYER" 4)))
      )
    (vl-cmdf "._-Layer" "_F" l "")
   )
)
Keep smile...

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to freeze a list of layers?
« Reply #10 on: September 30, 2008, 01:14:21 PM »
The layer command doesn't care if the layer exist or not and will ignore the current layer but will notify you of the fact.
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.

JohnK

  • Administrator
  • Seagull
  • Posts: 10657
Re: How to freeze a list of layers?
« Reply #11 on: September 30, 2008, 01:20:03 PM »
Command, vl-cmdf are SLOW! Please dont use them. Use either entmod or vl property functions to preform your operations.

I think that You need to verify if the layer exist before..
and verify if you aren't to a layer who need to be freeze
You can not freeze current layer.


that's only cause your using ``command''.  Use entmod and you can (I wouldn't recommend it but...):
Code: [Select]
( (lambda ( / laylst )
   (setq laylst (entget (tblobjname "LAYER" (getvar 'CLAYER))))
   (entmod
    (subst
     (cons 70 (boole 6 (cdr (assoc 70 laylst)) 1))
     (assoc 70 laylst)
     laylst))) )
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Andrea

  • Water Moccasin
  • Posts: 2372
Re: How to freeze a list of layers?
« Reply #12 on: September 30, 2008, 01:21:29 PM »
you'r right CAB,

Code: [Select]
(foreach l layerlisttofreeze
  (if (member (strcase l) (mapcar 'strcase (ai_table "LAYER" 4)))     
    (vl-cmdf "._-Layer" "_F" l "")
   )
)
Keep smile...

JohnK

  • Administrator
  • Seagull
  • Posts: 10657
Re: How to freeze a list of layers?
« Reply #13 on: September 30, 2008, 01:28:33 PM »


Just for the sake of conversation (Assuming the following code was a valid solution):
Code: [Select]
(foreach l layerlisttofreeze
  (if (member (strcase l) (mapcar 'strcase (ai_table "LAYER" 4)))     
    (vl-cmdf "._-Layer" "_F" l "")
   )
)

Why are you issuing the ``command'' over and over again for the list of layers? The layer command takes a list of layers...comma separated. Your taking a slow process and making it even slower!
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: How to freeze a list of layers?
« Reply #14 on: September 30, 2008, 01:42:09 PM »
Code: [Select]
Command: [color=red]-LA[/color]
-LAYER
Current layer:  "0"
Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte]:[color=red] F[/color]
Enter name list of layer(s) to freeze or <select objects>: [color=red]G8*[/color]
Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte]:

:-)
TheSwamp.org  (serving the CAD community since 2003)