See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Freeze/Thaw layer with specified text in layer name

  1. #1
    Active Member
    Join Date
    2011-10
    Posts
    83
    Login to Give a bone
    0

    Default Freeze/Thaw layer with specified text in layer name

    Hi all,

    can you help me with something?
    I would like to have a shortcut for freeze and thaw (toggle) all layers with specified text in layer name.
    For example I have a few layers:
    D_400$0$Structure-wall
    D_400$0$Structure-wall-under
    D_500$0$Structure-columns
    D_500$0$Structure-columns-under
    etc.

    Is there a possibility to have toggle between showing and hidding all layers with "Structure" inside?

    Thanks in advance.
    Artur

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,536
    Login to Give a bone
    1

    Default Re: Freeze/Thaw layer with specified text in layer name

    Quote Originally Posted by Arterius View Post
    Hi all,

    can you help me with something?
    I would like to have a shortcut for freeze and thaw (toggle) all layers with specified text in layer name.
    For example I have a few layers:
    D_400$0$Structure-wall
    D_400$0$Structure-wall-under
    D_500$0$Structure-columns
    D_500$0$Structure-columns-under
    etc.

    Is there a possibility to have toggle between showing and hidding all layers with "Structure" inside?

    Thanks in advance.
    Artur
    Consider the -LAYER Command:

    Code:
    (defun c:MyLayFrz () (command "._-layer" "_f" pause "") (princ))
    
    (defun c:MyLayThw () (command "._-layer" "_t" pause "") (princ))
    ... When prompted for layer name(s), simply enter *structure*, and all matching layers will be acted upon accordingly.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 64GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

  3. #3
    Active Member
    Join Date
    2011-10
    Posts
    83
    Login to Give a bone
    0

    Default Re: Freeze/Thaw layer with specified text in layer name

    Thanks BlackBox,

    I didn't know that asteriskes can bring so much good

    Thanks for help!

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,536
    Login to Give a bone
    1

    Default Re: Freeze/Thaw layer with specified text in layer name

    Quote Originally Posted by Arterius View Post
    Thanks BlackBox,

    I didn't know that asteriskes can bring so much good

    Thanks for help!
    You're welcome, Arterius; I'm happy to help.

    For reference, you find the WCMATCH function to be of particular interest now.

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

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 64GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

  5. #5
    Active Member
    Join Date
    2011-10
    Posts
    83
    Login to Give a bone
    0

    Default Re: Freeze/Thaw layer with specified text in layer name

    Thanks.

    BlackBox, is it possible to make it work like a toggle?
    When I type "MyLayFrz" layer go freeze, when type it again it thaw?

  6. #6
    Member
    Join Date
    2013-03
    Posts
    38
    Login to Give a bone
    1

    Default Re: Freeze/Thaw layer with specified text in layer name

    Code:
    (defun c:MyLayFrz (/ e cmdecho)
      (setq cmdecho (getvar 'cmdecho))
      (setvar 'cmdecho 0)
      (tblnext "layer" T)
      (while (setq e (tblnext "layer"))
        (if (wcmatch (strcase (cdr (assoc 2 e))) "*STRUCTURE*")
          (if (= (cdr (assoc 70 e)) 0)
    	(command "._-layer" "_f" (cdr (assoc 2 e)) "")
    	(command "._-layer" "_t" (cdr (assoc 2 e)) "")
          )
        )
      )
      (setvar 'cmdecho cmdecho)
      (princ)
    )

  7. #7
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,536
    Login to Give a bone
    1

    Default Re: Freeze/Thaw layer with specified text in layer name

    Quote Originally Posted by Arterius View Post
    BlackBox, is it possible to make it work like a toggle?
    When I type "MyLayFrz" layer go freeze, when type it again it thaw?
    Code:
    (defun c:MyLayFrz (/ layers)
      (if *MyLayFrz*
        (setq *MyLayFrz* (command "._-layer" "_t" *MyLayFrz* ""))
        (if
          (setq layers
    	     (getstring
    	       T
    	       "\nEnter name list of layer(s) to freeze: "
    	     )
          )
           (command "._-layer" "_f" (setq *MyLayFrz* layers) "")
        )
      )
      (princ)
    )
    Last edited by BlackBox; 2014-04-17 at 01:13 PM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 64GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

  8. #8
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,536
    Login to Give a bone
    0

    Default Re: Freeze/Thaw layer with specified text in layer name

    Quote Originally Posted by Frank Dux View Post
    Code:
    (defun c:MyLayFrz (/ e cmdecho)
      (setq cmdecho (getvar 'cmdecho))
      (setvar 'cmdecho 0)
      (tblnext "layer" T)
      (while (setq e (tblnext "layer"))
        (if (wcmatch (strcase (cdr (assoc 2 e))) "*STRUCTURE*")
          (if (= (cdr (assoc 70 e)) 0)
    	(command "._-layer" "_f" (cdr (assoc 2 e)) "")
    	(command "._-layer" "_t" (cdr (assoc 2 e)) "")
          )
        )
      )
      (setvar 'cmdecho cmdecho)
      (princ)
    )
    Just some observations on your code logic, if I may....

    If you're going to change user setting(s), then it is prudent to include error handling in order to restore one's settings, even on failure.

    There's no need to iterate the LayerTable, as the -LAYER Command support WCMATCH functionality; as coded you iterate the LayerTable, and for each-and-every-single LayerTableRecord that WCMATCHes "*STRUCTURE*" you call the -LAYER Command separately... If 100 LayerTableRecords match, then you've effectively called the Command 100 separate times, which is not very efficient as you could instead simply supply "*STRUCTURE*" to the -LAYER Command once, and yield the same result.

    Here's a quick example, with a drawing that has 100 LayerTableRecords that include "*STRUCTURE*" in the name, bench-marking your approach, an approach that iterates the LayerTable to build a list of strings and then only calls the -LAYER Command once vs. what I've posed here using WCMATCH from the outset:

    Sub-functions tested:

    Code:
    (vl-load-com)
    
    (defun fdux:FreezeStructureLayers (/ e layerName)
      (tblnext "layer" T)
      (while (setq e (tblnext "layer"))
        (if (wcmatch (strcase (setq layerName (cdr (assoc 2 e)))) "*STRUCTURE*")
          (command "._-layer" "_f" layerName "")
        )
      )
      (princ)
    )
    
    (defun fdux:FreezeStructureLayers2 (/ e layerName layersToFreeze)
      (tblnext "layer" T)
      (while (setq e (tblnext "layer"))
        (if (wcmatch (strcase (setq layerName (cdr (assoc 2 e)))) "*STRUCTURE*")
          (setq layersToFreeze (cons layerName layersToFreeze))
        )
      )
      (if layersToFreeze
        (command
          "._-layer"
          "_f"
          (vl-string-right-trim
    	","
    	(apply
    	  'strcat
    	  (mapcar (function (lambda (x) (strcat x ","))) layersToFreeze)
    	)
          )
          ""
        )
      )
      (princ)
    )
    
    (defun bbox:FreezeStructureLayers (/ layers)
      (command "._-layer" "_f" "*structure*" "")
      (princ)
    )


    Results from console, performing each sub-function 10 times only:

    Code:
    _$ (bench '(fdux:FreezeStructureLayers fdux:FreezeStructureLayers2 bbox:FreezeStructureLayers) '() 10)
    
    FDUX:FREEZESTRUCTURELAYERS
    Elapsed: 1498
    Average: 149.8000
    
    FDUX:FREEZESTRUCTURELAYERS2
    Elapsed: 141
    Average: 14.1000
    
    BBOX:FREEZESTRUCTURELAYERS
    Elapsed: 16
    Average: 1.6000
    ; 5 forms loaded from #<editor "<Untitled-0> loading...">
    _$


    Lastly, you're checking each matching layer's current state, which allows for user to freeze all using this routine, then modify some of them before attempting to toggle, which potentially results in a mixed state where some "*STRUCTURE*" layers are thawed, and some are frozen.

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

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 64GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

  9. #9
    Member
    Join Date
    2013-03
    Posts
    38
    Login to Give a bone
    0

    Default Re: Freeze/Thaw layer with specified text in layer name

    Thanks BlackBox ... after four years I am only now starting to get comfortable with AutoLisp and even at that I am still meandering at a basic level (I haven't even started with ActiveX/Visual Lisp yet). I like your code snippet, simple and to the point. I will probably end up copying your style in fact. I'll give due credit if I do.

    Have a nice weekend.

    FD

  10. #10
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,536
    Login to Give a bone
    0

    Default Re: Freeze/Thaw layer with specified text in layer name

    Quote Originally Posted by Frank Dux View Post
    Thanks BlackBox ... after four years I am only now starting to get comfortable with AutoLisp and even at that I am still meandering at a basic level (I haven't even started with ActiveX/Visual Lisp yet). I like your code snippet, simple and to the point. I will probably end up copying your style in fact. I'll give due credit if I do.

    Have a nice weekend.
    No worries; we all start somewhere... I'm just trying to save you some of the frustrations I've already had to learn the hard way.

    If I can get to where I am with development, you'll certainly become more proficient as well... I had a lot of help along the way from others much smarter than I, and often joke about the fact that I didn't even know what a LISP Defun was when I joined AUGI (November 2009). LoL

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

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 64GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

Page 1 of 2 12 LastLast

Similar Threads

  1. -Layer Freeze/Thaw in Viewport
    By Wish List System in forum AutoCAD Wish List
    Replies: 6
    Last Post: 2014-09-24, 04:03 AM
  2. Independent Model Space Layer On/Off and Freeze/Thaw control
    By Wish List System in forum AutoCAD Wish List
    Replies: 3
    Last Post: 2012-10-05, 09:12 PM
  3. Layer Freeze/Thaw toggle routine
    By jgardner.79905 in forum AutoLISP
    Replies: 5
    Last Post: 2010-02-01, 09:39 PM
  4. Unable to thaw Defpoints layer within a Layer State.
    By scotthop in forum AutoCAD General
    Replies: 4
    Last Post: 2008-04-04, 09:34 PM
  5. Replies: 10
    Last Post: 2004-07-23, 07:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •