nlao Posted April 12, 2011 Posted April 12, 2011 Hi, I am looking to lock multiple layers simultaneously by selection window. Or by clicking multiple times. The inbuilt lock layer (_laylck) command does not seem to support selection windows and only does one layer at a time. I would like to do mutiples. I am fairly new to LISP but fairly good at script writing (been on LT for several year, now on full!!!) I found this script on the forum; type "frz" to run lisp (defun c:frz () (setvar "cmdecho" 0) (setq data (enget (car (entsel))))) (setq laynme assoc 8 data)) (setq lay (cdr laynme)) (command "layer" "freeze" lay "") (princ)) Though autocad (2011) throws out an error (see below) Select object: ; error: no function definition: ENGETAny suggestions on how to modify the above a) to work and b) to do what i want? Or is there a better way? Thanks for your help! Quote
designerstuart Posted April 12, 2011 Posted April 12, 2011 your 'title' needs a semicolon at the beginning to be ignored by lisp but that didn't solve it edit: there is a syntax error somewhere as it doesn't load properly but i am not the one to say where...... someone will come along who can help soon! Quote
Lee Mac Posted April 12, 2011 Posted April 12, 2011 There is an error because the function 'enget' should be 'entget' in your code. I would approach it this way: (defun c:lck ( / b e i l s x ) (if (setq s (ssget)) (repeat (setq i (sslength s)) (if (not (member (setq l (cdr (assoc 8 (entget (ssname s (setq i (1- i))))))) x)) (progn (setq e (entget (tblobjname "LAYER" l)) x (cons l x) b (cdr (assoc 70 e)) ) (entmod (subst (cons 70 (logior 4 b)) (assoc 70 e) e)) ) ) ) ) (princ) ) I'm confused in that your thread speaks of locking layers, but the code you present is freezing them - which is it? Quote
designerstuart Posted April 12, 2011 Posted April 12, 2011 also, there are 12 "(" and 14 ")" which is not a good sign. has this code been hashed somewhere along the line? i tired to fix it, but fixed the syntax and then the error was a dodgy list. as i said...... a qualified lisper will be along shortly........ Quote
designerstuart Posted April 12, 2011 Posted April 12, 2011 lee i tried entget but still it wouldn't work.... is the code just badly done? Quote
Lee Mac Posted April 12, 2011 Posted April 12, 2011 lee i tried entget but still it wouldn't work.... is the code just badly done? That was the first thing I noticed, but yes, the code is littered with mistakes. A quick rewrite to get it working: (defun c:frz ( / e ) (if (setq e (car (entsel))) (command "_.-layer" "_freeze" (cdr (assoc 8 (entget e))) "") ) (princ) ) Quote
BlackBox Posted April 12, 2011 Posted April 12, 2011 (edited) That was the first thing I noticed, but yes, the code is littered with mistakes. A quick rewrite to get it working: (defun c:frz ( / e ) (if (setq e (car (entsel))) (command "_.-layer" "_freeze" (cdr (assoc 8 (entget e))) "") ) (princ) ) ._LAYFRZ ...? Edit: And for the thread title ._LAYLCK Edited April 12, 2011 by BlackBox Quote
alanjt Posted April 12, 2011 Posted April 12, 2011 Command: LA -LAYER Current layer: "C-PIPE" Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Fre eze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: LOCK Enter name list of layer(s) to lock or <select objects>: Select objects: Specify opposite corner: 6 found Quote
Lee Mac Posted April 12, 2011 Posted April 12, 2011 lol - looks like all the code in this thread is redundant Oh well, I enjoyed writing it Quote
alanjt Posted April 12, 2011 Posted April 12, 2011 lol - looks like all the code in this thread is redundant Oh well, I enjoyed writing it What was really nice was in the the pre 2009 versions, you could use a macro or LISP macro to select the property wanted (freeze, thaw, etc.) and then enter once to select (as it does in the core), but the 09 and on seemed to have screwed that up and it just goes back to the layer menu. Here's some of the first macros I ever wrote: ;ALLOWS YOU TO FREEZE BY ENTERING IN LAYER NAMES (WILD CARDS ALLOWED) (defun c:LAZ () (command "-layer" "freeze" ) (princ)) ;ALLOWS YOU TO TURN OFF LAYERS BY ENTERING IN LAYER NAMES (WILD CARDS ALLOWED) (defun c:LAF () (command "-layer" "off" ) (princ)) ;LOCK LAYER(S) BY PICK OR BY NAME (WILD CARDS ALLOWED) (defun c:LK () (command "-layer" "lock" ) (princ)) ;UNLOCK LAYER(S) BY PICK OR BY NAME (WILD CARDS ALLOWED) (defun c:LU () (command "-layer" "unlock" ) (princ)) You could type in the layer filter or enter/right-click once and select away. Quote
nlao Posted April 13, 2011 Author Posted April 13, 2011 [ATTACH]26988[/ATTACH] -LAYER AH I hadn't even thought about running the command line option! Duh! I can write a button macro to get through to that point and quickly lock several layers at once again. lol - looks like all the code in this thread is redundant Oh well, I enjoyed writing it I enjoyed reading it. Beginning to understand how LISP works now! Thanks guys! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.