tzframpton Posted April 21, 2010 Share Posted April 21, 2010 I don't claim to know LISP at all, but I sure can monkey with code and make reeeeeeally simple routines all by myself. :wink: So anyways, I created two extremely useful LISPs today while working on a multiple scale drawing. I was wondering if I could combine the two, so that it would freeze and thaw the layers I'm wanting to manipulate sort of like a "toggle". I'm assuming this will make me dive into the (if) statement, or expression, or argument.... I can't ever remember which one the operators are called, if it even is an operator. So here's my two separate test LISP files I made, which basically is a command line -LAYER script is all.... (DEFUN C:4IN (/ ) (command "._layer" "_t" "*-048" "_t" "*-4.5" "_f" "*-096" "_f" "*-09" "") (princ) ) (DEFUN C:8IN (/ ) (command "._layer" "_f" "*-048" "_f" "*-4.5" "_t" "*-096" "_t" "*-09" "") (princ) ) So my question to all would be to (1) point me in the right direction, or maybe with some sample code, guide me in combining these and (2) possible show me how to control the Layer entities without using this outdated method of command line style scripting. Just a couple of humble requests is all, I technically have what I need and it works well but I'm interested in expanding my skills to super dooper novice to just super novice. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
David Bethel Posted April 21, 2010 Share Posted April 21, 2010 Maybe something like this: (defun c:mylay (/ input tl fl) (initget 1 "4 8") (setq input (getkword "\n4 or 8: ")) (cond ((= input "4") (setq tl (list "*048" "*-4.5") ;THAW LIST fl (list "*096" "*-09"))) ;FREEZE LIST ((= input "8") (setq fl (list "*048" "*-4.5") ;FREEZE LIST tl (list "*096" "*-09")))) ;THAW LIST (command "_.LAYER") (foreach l tl (command "_.Thaw" l)) (foreach l fl (command "_Freeze" l)) (command "") (princ)) You can manipulate the freeze and thaw lists, and add more if you need to. -David Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 22, 2010 Share Posted April 22, 2010 If you wanted to avoid the command line call, here is another way: (defun c:laytog ( / GetLayers Freeze Thaw l1 l2 ) ;; Lee Mac ~ 22.04.10 (defun GetLayers ( wc / def n lst ) (while (setq def (tblnext "LAYER" (not def))) (if (wcmatch (setq n (cdr (assoc 2 def))) wc) (setq lst (cons (tblobjname "LAYER" n) lst)))) lst) (defun Freeze ( layer / dx70 el ) (setq dx70 (cdr (assoc 70 (setq el (entget layer))))) (entmod (subst (cons 70 (boole 7 1 dx70)) (assoc 70 el) el))) (defun Thaw ( layer / dx70 el ) (setq dx70 (cdr (assoc 70 (setq el (entget layer))))) (entmod (subst (cons 70 (boole 4 1 dx70)) (assoc 70 el) el))) (setq l1 (GetLayers "*-4.5") l2 (GetLayers "*-09")) (cond ( (setq *flag* (not *flag*)) (mapcar (function Freeze) l1) (mapcar (function Thaw) l2)) ( (mapcar (function Freeze) l2) (mapcar (function Thaw) l1))) (princ)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 22, 2010 Share Posted April 22, 2010 Another, if you want to be fancy (defun c:laytog ( / GetLayers FTLayer l1 l2 ) ;; Lee Mac ~ 22.04.10 (defun GetLayers ( wc / def n lst ) (while (setq def (tblnext "LAYER" (not def))) (if (wcmatch (setq n (cdr (assoc 2 def))) wc) (setq lst (cons (tblobjname "LAYER" n) lst)))) lst) (defun FTLayer ( layer freeze / dx70 el ) (setq dx70 (cdr (assoc 70 (setq el (entget layer))))) (entmod (subst (cons 70 (boole (+ 4 (* freeze 3)) 1 dx70)) (assoc 70 el) el))) (setq l1 (GetLayers "*-4.5") l2 (GetLayers "*-09")) (mapcar (function (lambda ( layers flag ) (mapcar (function (lambda ( layer ) (FTLayer layer flag) ) ) layers ) ) ) (list l1 l2) (if (setq *flag* (not *flag*)) '(1 0) '(0 1)) ) (princ)) Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted April 22, 2010 Share Posted April 22, 2010 No flaming please... this is not meant to discredit David's or Lee's code ..... but..... strictly combining your original code into a "toggle".. how about this? This example does make an assumption that there is a layer named "A-048", you can change this --- or if you don't want to make any assumptions, you would have to iterate the layer collection, checking each of the *-048" layers, and then make a determination if their freeze/thaw status isn't the same for all... Also, you might want to set layer 0 current first so that you don't try to freeze the current layer. (defun c:laytog () (if (eq 1 (logand 1 (cdr (assoc 70 (tblsearch "layer" "A-048"))))) (command "._layer" "_t" "*-048" "_t" "*-4.5" "_f" "*-096" "_f" "*-09" "") (command "._layer" "_f" "*-048" "_f" "*-4.5" "_t" "*-096" "_t" "*-09" "") ) ) Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 22, 2010 Share Posted April 22, 2010 Just for reference sake. When using -layer, you don't have to separate your strings. eg. (command "._layer" "_t" "*-048" "_t" "*-4.5" "_f" "*-096" "_f" "*-09" "") could be executed as: (command "_.layer" _t" "*-048,*-4.5" "_f" "*-096,*-09" "") Not that there's anything wrong with your code or David's or Lee's. Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 22, 2010 Share Posted April 22, 2010 FLAME!! Also, you might want to set layer 0 current first so that you don't try to freeze the current layer. A most excellent point. (if (wcmatch (getvar 'clayer) "*-096,*-09") (command "_.layer" "_t" "0" "_s" "0" "")) Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted April 22, 2010 Share Posted April 22, 2010 FLAME!!Thanks, I knew it was coming.... Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 22, 2010 Share Posted April 22, 2010 Thanks, I knew it was coming.... Hey, I was following suite with just modifying Tannar's work. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 22, 2010 Share Posted April 22, 2010 (2) possible show me how to control the Layer entities without using this outdated method of command line style scripting I was just providing an alternative Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 22, 2010 Share Posted April 22, 2010 I was just providing an alternative Nothing wrong with that. Nothing wrong with using command if that's all one knows. Hell, I still have a few specific layer on/off macros that use command and I don't see myself ever editing them. Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted April 22, 2010 Share Posted April 22, 2010 I was just providing an alternative Nothing wrong with that. Nothing wrong with using command if that's all one knows. Hell, I still have a few specific layer on/off macros that use command and I don't see myself ever editing them. I agree with both. There are always many ways to attack a problem. Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 22, 2010 Share Posted April 22, 2010 I agree with both. There are always many ways to attack a problem. My favorite is just pawning it off on someone else. Quote Link to comment Share on other sites More sharing options...
tzframpton Posted April 22, 2010 Author Share Posted April 22, 2010 Awesome guys, thanks for the help. McSwain raises an excellent point of the "current layer" issue. Before I continue, I have another question, is there a way when I'm in the VLIDE that I can just run the program straight into AutoCAD without having to Ctrl+S and drag/drop the file back into AutoCAD like I'm doing?? And Alan, thanks for that tip about combining the strings. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 22, 2010 Share Posted April 22, 2010 Yes, here: Quote Link to comment Share on other sites More sharing options...
tzframpton Posted April 22, 2010 Author Share Posted April 22, 2010 Sweet!! Thanks Lee. Why didn't I ask this before?? Alright, gonna monkey with the code..... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 22, 2010 Share Posted April 22, 2010 No worries, not sure if you've seen this before, if not, its worth a read Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 22, 2010 Share Posted April 22, 2010 Yes, here: [ATTACH]19103[/ATTACH] or Control + Alt + E Quote Link to comment Share on other sites More sharing options...
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.