Author Topic: entmake list of layers, locking one layer in the list  (Read 2959 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Bull Frog
  • Posts: 327
entmake list of layers, locking one layer in the list
« on: December 02, 2019, 07:00:08 PM »
How do I set one of several layers locked.




Code - Auto/Visual Lisp: [Select]
  1. (defun _addlayer (name color ltype plot)
  2.     (cond ((not (tblsearch "layer" name))
  3.            (entmakex (list '(0 . "LAYER")
  4.                            '(100 . "AcDbSymbolTableRecord")
  5.                            '(100 . "AcDbLayerTableRecord")
  6.                            '(70 . 0) ;;;referencing group code 70 here. The flag for a locked layer is 4.
  7.                            (cons 2 name)
  8.                            (cons 62 color)
  9.                            (cons 70 flag);; add element to list
  10.                            (cons 6
  11.                                  (cond ((tblobjname "ltype" ltype))
  12.                                        ("continuous")
  13.                                  )
  14.                            )
  15.                            (cons 290 plot)
  16.                            ;;1 = plottable 0 = not=plottable
  17.                      );; end list
  18.             );; end entmake
  19.           );; tblsearch
  20.           ((tblobjname "layer" name))
  21.     );; cond
  22.   );;   end _addlayer
  23.  
  24. (_addlayer "layername" 1 4 "continous" 1) ;;indicate flag as 4
  25.  
  26. )
  27.  

This doesn't seem to work.

J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

stevej

  • Newt
  • Posts: 30
Re: entmake list of layers, locking one layer in the list
« Reply #1 on: December 02, 2019, 08:53:08 PM »
Example: To lock and freeze the grid and mark layers (if you're not averse to using "command"):

Code: [Select]
(command "_.-Layer" "lock" "grid,mark" "freeze" "grid,mark" "")
Separate layer names with commas and no spaces.

Steve
« Last Edit: December 02, 2019, 08:58:26 PM by stevej »

kpblc

  • Bull Frog
  • Posts: 396
Re: entmake list of layers, locking one layer in the list
« Reply #2 on: December 02, 2019, 11:56:10 PM »
Another one:
Code - Auto/Visual Lisp: [Select]
  1. (defun t1 (/ adoc)
  2.   (foreach item '("layer1" "layer2" "layer3")
  3.     (vl-catch-all-apply
  4.       (function (lambda () (vla-put-lock (vla-item (vla-get-layers adoc) item) :vlax-true)))
  5.       ) ;_ end of vl-catch-all-apply
  6.     ) ;_ end of foreach
  7.   (vla-endundomark adoc)
  8.   ) ;_ end of defun
Sorry for my English.

Dlanor

  • Bull Frog
  • Posts: 263
Re: entmake list of layers, locking one layer in the list
« Reply #3 on: December 03, 2019, 02:52:53 AM »
How do I set one of several layers locked.

Maybe

Code - Auto/Visual Lisp: [Select]
  1. (defun _addlayer (name color flag ltype plot)
  2.     (cond ((not (tblsearch "layer" name))
  3.            (entmakex (list '(0 . "LAYER")
  4.                            '(100 . "AcDbSymbolTableRecord")
  5.                            '(100 . "AcDbLayerTableRecord")
  6.                            (if (> flag 0) (cons 70 flag)  '(70 . 0)) ;;;referencing group code 70 here. The flag for a locked layer is 4.
  7.                            (cons 2 name)
  8.                            (cons 62 color)
  9.                            (cons 6
  10.                                  (cond ((tblobjname "ltype" ltype))
  11.                                        ("continuous")
  12.                                  )
  13.                            )
  14.                            (cons 290 plot)
  15.                            ;;1 = plottable 0 = not=plottable
  16.                      );; end list
  17.             );; end entmake
  18.           );; tblsearch
  19.           ((tblobjname "layer" name))
  20.     );; cond
  21.   );;   end _addlayer
  22.  
  23. (_addlayer "layername" 1 4 "continous" 1) ;;indicate flag as 4
  24.  
  25. )
  26.  

« Last Edit: December 03, 2019, 02:56:18 AM by Dlanor »

tombu

  • Bull Frog
  • Posts: 289
  • ByLayer=>Not0
Re: entmake list of layers, locking one layer in the list
« Reply #4 on: December 03, 2019, 07:24:29 AM »
Creating Layer State las files that can easily be imported into any drawing or template is another option. They can be applied to a Viewport to create overrides as well. They can also be imported from DWG's, DWT's & DWS's.
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

jlogan02

  • Bull Frog
  • Posts: 327
Re: entmake list of layers, locking one layer in the list
« Reply #5 on: December 03, 2019, 11:29:52 AM »
Went briefly through my mind. Will test this.
Code - Auto/Visual Lisp: [Select]
  1. IF...


How do I set one of several layers locked.

Maybe

Code - Auto/Visual Lisp: [Select]
  1. (defun _addlayer (name color flag ltype plot)
  2.     (cond ((not (tblsearch "layer" name))
  3.            (entmakex (list '(0 . "LAYER")
  4.                            '(100 . "AcDbSymbolTableRecord")
  5.                            '(100 . "AcDbLayerTableRecord")
  6.                            (if (> flag 0) (cons 70 flag)  '(70 . 0)) ;;;referencing group code 70 here. The flag for a locked layer is 4.
  7.                            (cons 2 name)
  8.                            (cons 62 color)
  9.                            (cons 6
  10.                                  (cond ((tblobjname "ltype" ltype))
  11.                                        ("continuous")
  12.                                  )
  13.                            )
  14.                            (cons 290 plot)
  15.                            ;;1 = plottable 0 = not=plottable
  16.                      );; end list
  17.             );; end entmake
  18.           );; tblsearch
  19.           ((tblobjname "layer" name))
  20.     );; cond
  21.   );;   end _addlayer
  22.  
  23. (_addlayer "layername" 1 4 "continous" 1) ;;indicate flag as 4
  24.  
  25. )
  26.  


Currently what I'm doing.

Example: To lock and freeze the grid and mark layers (if you're not averse to using "command"):

Code: [Select]
(command "_.-Layer" "lock" "grid,mark" "freeze" "grid,mark" "")
Separate layer names with commas and no spaces.

Steve

Considered this early on but went with the command option. This method seemed a lil overkill for just locking a layer
Another one:
Code - Auto/Visual Lisp: [Select]
  1. (defun t1 (/ adoc)
  2.   (foreach item '("layer1" "layer2" "layer3")
  3.     (vl-catch-all-apply
  4.       (function (lambda () (vla-put-lock (vla-item (vla-get-layers adoc) item) :vlax-true)))
  5.       ) ;_ end of vl-catch-all-apply
  6.     ) ;_ end of foreach
  7.   (vla-endundomark adoc)
  8.   ) ;_ end of defun

Have never looked into Layer State Las files. Thanks for the idea
Creating Layer State las files that can easily be imported into any drawing or template is another option. They can be applied to a Viewport to create overrides as well. They can also be imported from DWG's, DWT's & DWS's.

Thanks for all the ideas folks. Much appreciated.
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org