Author Topic: Refreeze a list of layers!  (Read 2019 times)

0 Members and 1 Guest are viewing this topic.

jmcshane

  • Newt
  • Posts: 83
Refreeze a list of layers!
« on: March 11, 2014, 03:01:11 PM »
Hi, having a brain freeze here at the minute!
If I Thaw a list of layers like so:
Code: [Select]
(vlax-for LayerName  LayerTable
    (if (= (vla-get-Freeze LayerName) :vlax-true)
      (progn
        (setq LayerFreezeList (acad_strlsort (cons (vla-get-name LayerName) LayerFreezeList)))
        (vla-put-Freeze LayerName :vlax-false)
        )
      )
    )
What is the most elegant way of freezing that list of layers again?

Thanks in advance.

John
John.

Civil 3D 2021. Windows 10

BlackBox

  • King Gator
  • Posts: 3770
Re: Refreeze a list of layers!
« Reply #1 on: March 11, 2014, 03:16:46 PM »
Using your symbols:

Code - Auto/Visual Lisp: [Select]
  1. (vlax-for LayerName LayerTable
  2.   (if (= (vla-get-Freeze LayerName) :vlax-true)
  3.     (progn
  4.       (setq LayerFreezeList (cons LayerName LayerFreezeList))
  5.       (vla-put-Freeze LayerName :vlax-false)
  6.     )
  7.   )
  8. )
  9.  
  10. ;; <-- do it
  11.  
  12. (foreach LayerName LayerFreezeList
  13.   (vla-put-freeze LayerName :vlax-true)
  14. )
  15.  
« Last Edit: March 11, 2014, 04:18:24 PM by BlackBox »
"How we think determines what we do, and what we do determines what we get."

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Refreeze a list of layers!
« Reply #2 on: March 11, 2014, 03:47:13 PM »
You will need the layer object, not the name. Don't create a list from vla-get-name, just create a list from each layer object.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

BlackBox

  • King Gator
  • Posts: 3770
Re: Refreeze a list of layers!
« Reply #3 on: March 11, 2014, 03:49:32 PM »
You will need the layer object, not the name. Don't create a list from vla-get-name, just create a list from each layer object.

Good catch; I saw the usage of LayerName symbol while iterating LayerTable, and overlooked the OP's call to vla-Get-Name, when removing the unnecessary sort after each append.

Cheers
"How we think determines what we do, and what we do determines what we get."

jmcshane

  • Newt
  • Posts: 83
Re: Refreeze a list of layers!
« Reply #4 on: March 11, 2014, 03:51:57 PM »
Thanks guys, but my head is melted here.
How do you mean get the layer object?
John.

Civil 3D 2021. Windows 10

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Refreeze a list of layers!
« Reply #5 on: March 11, 2014, 03:56:56 PM »
Thanks guys, but my head is melted here.
How do you mean get the layer object?
Here is a simple example:
(vlax-ename->vla-object (tblobjname "layer" "0"))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Refreeze a list of layers!
« Reply #6 on: March 11, 2014, 03:59:33 PM »
Code: [Select]
(vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
  (if (eq (vla-get-freeze layer) :vlax-true)
    (progn (vla-put-freeze layer :vlax-false)
   (setq thawedLayers (cons layer thawedLayers))
    )
  )
)




(foreach layer thawedLayers (vla-put-freeze layer :vlax-true))
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

jmcshane

  • Newt
  • Posts: 83
Re: Refreeze a list of layers!
« Reply #7 on: March 11, 2014, 04:04:18 PM »
Sorry guys, the cleaner is kicking me out here. I have been staring at this computer for the last 10 hours.
I will have to come back to this tomorrow.
Thanks for taking the time to reply.

John
John.

Civil 3D 2021. Windows 10

BlackBox

  • King Gator
  • Posts: 3770
Re: Refreeze a list of layers!
« Reply #8 on: March 11, 2014, 04:16:02 PM »
Thanks guys, but my head is melted here.
How do you mean get the layer object?

According to your code in the OP, you already have each LayerTableRecord Object, when you iterate the LayerTable via vlax-For... You just used the 'LayerName' symbol for same.

You were then conditionally storing the extracted layer name (string) from the LayerTableRecord Object to the 'LayerFreezeList' variable, and sorting, etc.

Instead, you should be conditionally storing the LayerTableRecord Object to your list, and then iterating that list using foreach, as shown above.

HTH
"How we think determines what we do, and what we do determines what we get."

jmcshane

  • Newt
  • Posts: 83
Re: Refreeze a list of layers!
« Reply #9 on: March 12, 2014, 04:44:47 AM »
So I was nearly there!!!
Thanks a million for the advice guys and the examples! :-)
John.

Civil 3D 2021. Windows 10