Author Topic: Freeze all layer  (Read 5943 times)

0 Members and 1 Guest are viewing this topic.

Humbertogo

  • Guest
Freeze all layer
« on: April 27, 2006, 02:14:19 AM »
I try to Freeze all layer with (command "_.-LAYER" "F" "*"  it working but i get Error
Error: AutoCAD variable setting rejected: "clayer" "0"; error: An error has
occurred inside the *error* functionAutoCAD variable setting rejected: "clayer"
"0"

do know any one why this err occurred and how to fix it

Thanks

FengK

  • Guest
Re: Freeze all layer
« Reply #1 on: April 27, 2006, 02:48:37 AM »
Humbertogo,

You can't free the current layer.  Here is a quick fix:

(vl-catch-all-apply
  (function (lambda ()
         (command "-LAYER" "F" "*" "")
       )
  )
)

- KF

Humbertogo

  • Guest
Re: Freeze all layer
« Reply #2 on: April 27, 2006, 03:17:59 AM »
I have use your code but i still have the err

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Freeze all layer
« Reply #3 on: April 27, 2006, 04:02:54 AM »
Code: [Select]
(defun unfrozen ()
  (vlax-map-collection
    (vla-get-layers
      (vla-get-activedocument
(vlax-get-acad-object)
      ) ;_  vla-get-activedocument
    ) ;_  vla-get-layers
    (function
      (lambda (x)
(vl-catch-all-apply
  (function vla-put-freeze)
  (list x :vlax-false)
) ;_  vl-catch-all-apply
      ) ;_  lambda
    ) ;_  function
  ) ;_  vlax-map-collection
  (vla-regen
    (vla-get-activedocument
      (vlax-get-acad-object)
    ) ;_  vla-get-activedocument
    1
  ) ;_  vla-regen
  (princ "\nLayers are unfrozen ")
) ;_  defun
(defun frozen ()
  (vlax-map-collection
    (vla-get-layers
      (vla-get-activedocument
(vlax-get-acad-object)
      ) ;_  vla-get-activedocument
    ) ;_  vla-get-layers
    (function
      (lambda (x)
(vl-catch-all-apply
  (function vla-put-freeze)
  (list x :vlax-true)
) ;_  vl-catch-all-apply
      ) ;_  lambda
    ) ;_  function
  ) ;_  vlax-map-collection
  (vla-regen
    (vla-get-activedocument
      (vlax-get-acad-object)
    ) ;_  vla-get-activedocument
    1
  ) ;_  vla-regen
  (princ "\nLayers are frozen ")
) ;_  defun
(unfrozen)
(frozen)

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Freeze all layer
« Reply #4 on: April 27, 2006, 04:36:20 AM »
This should do the stuff (you may need to call vl-load-com to initialize ActiveX support):
Code: [Select]
;
; == Function MePutAllLayers
; Controls Freeze, LayerOn, Lock, Plottable or ViewportDefault for all Layers.
; Arguments [Type]:
;   Sym = Symbol [SYM]:
;   - 'vla-put-Freeze
;   - 'vla-put-LayerOn
;   - 'vla-put-Lock
;   - 'vla-put-Plottable
;   - 'vla-put-ViewportDefault
;   Mde = Mode [BOOLEAN]:
;   - :vlax-true
;   - :vlax-false
; Return [Type]:
;   > Null
; Notes:
;   - Some symbols require a vla-regen to make the changes visible.
;
(defun MePutAllLayers (Sym Mde / AcaDoc)
 (setq AcaDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
 (vlax-for Obj (vla-get-Layers AcaDoc)
  (vl-catch-all-error-p
   (vl-catch-all-apply Sym (list Obj Mde))
  )
 )
 (princ)
)

Use:
(MePutAllLayers 'vla-put-Freeze :vlax-true)

Edited: Notes added
« Last Edit: April 27, 2006, 04:40:47 AM by Jürg Menzi »
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

Humbertogo

  • Guest
Re: Freeze all layer
« Reply #5 on: April 27, 2006, 06:08:31 AM »
Thanks

Sdoman

  • Guest
Re: Freeze all layer
« Reply #6 on: April 27, 2006, 07:48:13 AM »
I try to Freeze all layer with (command "_.-LAYER" "F" "*"  it working but i get Error
Error: AutoCAD variable setting rejected: "clayer" "0"; error: An error has
occurred inside the *error* functionAutoCAD variable setting rejected: "clayer"
"0"

do know any one why this err occurred and how to fix it

Thanks

My guess is that the *error* function is crashing because it is trying to set the CLAYER variable to a layer that is frozen.
 
At the start of your routine, i suggest saving the CLAYER name and all layer states before modifying.  Then in the *error* function, i would restore the layer states and then the CLAYER variable, in that order.

CADaver

  • Guest
Re: Freeze all layer
« Reply #7 on: April 27, 2006, 09:16:07 AM »
Gotta go with Steve on this one.  Humbertogo, can you post the whole code you're using??

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Freeze all layer
« Reply #8 on: April 27, 2006, 10:45:38 AM »
Edit: Modified to remove poor coding precident --

Code: [Select]
(defun foo ( / clayer )
    (setq clayer (getvar "clayer"))
    (vlax-map-collection
        (vlax-get
            (vlax-get
                (vlax-get-acad-object)
               'ActiveDocument
            )
           'Layers
        )
       '(lambda ( layer )
            (if (/= clayer (vlax-get layer 'Name))
                (vlax-put layer 'Freeze :vlax-true)
            )
        )
    )
)
« Last Edit: April 27, 2006, 01:39:07 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Freeze all layer
« Reply #9 on: April 27, 2006, 11:08:46 AM »
Perhaps:

Code: [Select]
(defun freeze_all (/ doc lays clay lay)
  (setq doc  (vla-get-activedocument (vlax-get-acad-object))
lays (vla-get-layers doc)
clay (vla-get-name (vla-get-activelayer doc))
  )
  (vlax-for lay lays
    (if (/= (vla-get-name lay) clay)
      (vla-put-freeze lay :vlax-true)
    )
  )
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CADaver

  • Guest
Re: Freeze all layer
« Reply #10 on: April 27, 2006, 01:13:25 PM »
you guys are just giving away the fish market now.  What happened to "teach 'em (me) how to fish"???

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Freeze all layer
« Reply #11 on: April 27, 2006, 01:29:41 PM »
Ron,
If you look at Jürg function it is similar to yours but he uses the catch-all to prevent the error.
Where you test each layer. This is his code modified for freeze only.
Code: [Select]
(defun meFreezeAllLayers (/ acadoc)
  (setq acadoc (vla-get-activedocument (vlax-get-acad-object)))
  (vlax-for obj (vla-get-layers acadoc)
    (vl-catch-all-error-p
      (vl-catch-all-apply 'vla-put-freeze (list obj :vlax-true))
    )
  )
  (princ)
)

Not sure if the local var is needed. If not then this.
Code: [Select]
(defun meFreezeAllLayers ()
  (vlax-for obj (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
    (vl-catch-all-error-p
      (vl-catch-all-apply 'vla-put-freeze (list obj :vlax-true))
    )
  )
  (princ)
)

So it's a very useful function for changing layer states.
Thanks  Jürg
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.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Freeze all layer
« Reply #12 on: April 27, 2006, 01:34:49 PM »
you guys are just giving away the fish market now.  What happened to "teach 'em (me) how to fish"???

It young fish,  it is necessary bring up :-)

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Freeze all layer
« Reply #13 on: April 27, 2006, 01:59:43 PM »
Interesting CAB....would it be better to wite the function with less variables like this?

Code: [Select]
(defun freeze_all (/ lay)
  (vlax-for lay (vla-get-layers
  (vla-get-activedocument (vlax-get-acad-object))
)
    (if (/= (vla-get-name lay)
    (vla-get-name
      (vla-get-activelayer
(vla-get-activedocument (vlax-get-acad-object))
      )
    )
)
      (vla-put-freeze lay :vlax-true)
    )
  )
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Freeze all layer
« Reply #14 on: April 27, 2006, 02:46:49 PM »
Interesting CAB....would it be better to wite the function with less variables like this?

Code: [Select]
(defun freeze_all (/ lay)
  (vlax-for lay (vla-get-layers
  (vla-get-activedocument (vlax-get-acad-object))
)
    (if (/= (vla-get-name lay)
    (vla-get-name
      (vla-get-activelayer
(vla-get-activedocument (vlax-get-acad-object))
      )
    )
)
      (vla-put-freeze lay :vlax-true)
    )
  )
  (princ)
)

Hi Ron, if you don't mind me cutting in --

In my opinion it would be better if you captured the name of the current layer to a variable before entering the layer iteration code. That is, you pay an unneccessary performance penalty to retrieve it on every iteration.

While I probably would favour getvar over the activex equivalent, I coded the following per your example --

Code: [Select]
(defun freeze_all ( / clayer document )

    (setq clayer
        (vla-get-name
            (vla-get-activelayer
                (setq document
                    (vla-get-activedocument
                        (vlax-get-acad-object)
                    )
                )   
            )
        )
    )

    (vlax-for layer (vla-get-layers document)
        (if (/= clayer (vla-get-name layer))
            (vla-put-freeze layer :vlax-true)
        )   
    )

    (princ)
   
)

Cheers.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst