TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jlogan02 on December 02, 2019, 07:00:08 PM

Title: entmake list of layers, locking one layer in the list
Post by: jlogan02 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.

Title: Re: entmake list of layers, locking one layer in the list
Post by: stevej 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
Title: Re: entmake list of layers, locking one layer in the list
Post by: kpblc 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
Title: Re: entmake list of layers, locking one layer in the list
Post by: Dlanor 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.  

Title: Re: entmake list of layers, locking one layer in the list
Post by: tombu 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.
Title: Re: entmake list of layers, locking one layer in the list
Post by: jlogan02 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.
Title: Re: entmake list of layers, locking one layer in the list
Post by: JohnK on December 03, 2019, 12:57:50 PM
http://www.theswamp.org/index.php?topic=55159.msg594386#msg594386