Manila Wolf Posted February 23, 2012 Posted February 23, 2012 Does anyone have a lisp that will isolate or turn off all layers that have a block of a certain name drawn on them? Except if it's the current layer. For example, I have multiple layers with a blocks named "PartTag" residing on them. I would like to with a single click turn off (or freeze) all the layers where this block resides. Thanks to anybody who may help with this Quote
Lee Mac Posted February 23, 2012 Posted February 23, 2012 Try something like this: (defun c:TurnOffBlockLayers ( / en in la ls ss ) (while (progn (setvar 'ERRNO 0) (setq en (car (entsel "\nSelect Block: "))) (cond ( (= 7 (getvar 'ERRNO)) (princ "\nMissed, try again.") ) ( (eq 'ENAME (type en)) (if (not (eq "INSERT" (cdr (assoc 0 (entget en))))) (princ "\nObject is not a Block.") ) ) ) ) ) (if en (progn (setq ss (ssget "_X" (list '(0 . "INSERT") (assoc 2 (entget en)) (cons 410 (if (= 1 (getvar 'CVPORT)) (getvar 'CTAB) "Model" ) ) ) ) ) (repeat (setq in (sslength ss)) (setq la (cdr (assoc 8 (entget (ssname ss (setq in (1- in))))))) (if (not (member la ls)) (setq ls (cons la ls)) ) ) (foreach la ls (setq la (entget (tblobjname "LAYER" la))) (entmod (subst (cons 62 (- (abs (cdr (assoc 62 la))))) (assoc 62 la) la ) ) ) ) ) (princ) ) Quote
David Bethel Posted February 23, 2012 Posted February 23, 2012 (edited) Or maybe a bit more brutish: [b][color=BLACK]([/color][/b]defun c:offins [b][color=FUCHSIA]([/color][/b]/ ss is en ln ll[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]or [b][color=MAROON]([/color][/b]not ss[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]/= [b][color=GREEN]([/color][/b]sslength ss[b][color=GREEN])[/color][/b] 1[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]princ [color=#2f4f4f]"\nSelect INSERT: "[/color][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq is [b][color=NAVY]([/color][/b]ssget [color=#2f4f4f]"X"[/color] [b][color=MAROON]([/color][/b]list [b][color=GREEN]([/color][/b]cons 0 [color=#2f4f4f]"INSERT"[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]assoc 2 [b][color=BLUE]([/color][/b]entget [b][color=RED]([/color][/b]ssname ss 0[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]setq en [b][color=MAROON]([/color][/b]ssname is 0[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq ln [b][color=MAROON]([/color][/b]cdr [b][color=GREEN]([/color][/b]assoc 8 [b][color=BLUE]([/color][/b]entget en[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]and [b][color=MAROON]([/color][/b]/= ln [b][color=GREEN]([/color][/b]getvar [color=#2f4f4f]"CLAYER"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]member ln ll[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq ll [b][color=GREEN]([/color][/b]cons ln ll[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]ssdel en is[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]command [color=#2f4f4f]"_.LAYER"[/color][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]foreach l ll [b][color=NAVY]([/color][/b]command [color=#2f4f4f]"_Off"[/color] l[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]command [color=#2f4f4f]""[/color][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] -David Edited March 13, 2012 by David Bethel Compress layer list Quote
pBe Posted February 23, 2012 Posted February 23, 2012 (defun c : o f f i n s (/ ss is en ln ll)..... -David Eerie.... Quote
Manila Wolf Posted February 27, 2012 Author Posted February 27, 2012 Lee and David, Many thanks for the two versions that answer my request. More time savers for me, so I am indeed grateful. Quote
Manila Wolf Posted March 13, 2012 Author Posted March 13, 2012 Hi guys, I am using these lisps frequently but stumbled accross an AutoCAD anomaly. I call up David's "Offins" lisp in a toolbutton macro selecting the lisp by use of AutoCAD's select previous feature after selecting a block to make the block layer current. This indeed does work, unless I have hundreds of blocks in the drawing. AutoCAD throws up the statement: - Select objects: p 1067 found Select objects: USER INPUT IS TOO LONG. My goal is to click on a block, make the layer that the selected block is on the current layer, then turn off all the other layers that that block resides on, but leave the now current layer on. I suspect the AutoCAD limitation on the amount of oblects that can be called up by the previous command is hard fixed, so is there a way that the lisp can simply be tweaked to perform as I would like it? Quote
pBe Posted March 13, 2012 Posted March 13, 2012 Select objects: p 1067 found Select objects: Are you passing the "P" within the offins command? Quote
Manila Wolf Posted March 13, 2012 Author Posted March 13, 2012 Are you passing the "P" within the offins command? Hi PBe, I call up the "P" after invoking the offins command. Here is my macro: - (hahaha - Don't laugh. It nearly worked). ^C^C_e;all;;oops;_atttaglay p;;-layer u *;;_layon;(setq ss1 (ssget));\;_ai_molc;!ss1;E !ss1;;oops;_offins p;;_laylock;p;;-layer LO 0;; The "p" does not work with the TurnOffBlockLayers lisp. Quote
pBe Posted March 13, 2012 Posted March 13, 2012 Hi PBe, ^C^C_e;all;;oops;_atttaglay p;;-layer u *;;_layon;(setq ss1 (ssget));\;_ai_molc;!ss1;E !ss1;;oops;_offins p;;_laylock;p;;-layer LO 0;; wow.. you lost me there... that is all greek to me ManilaWolf At any rate.. I cant tell what part of that macro stalls when you pass the "p" argument, but I doubt that its within offins routine. unless you indeed have 1067 blocks on your drawing. The code uses a filter for blocks. Besides i cant quite put my finger on these lines _e;all;oops; and E !ss1;;oops (the logic behind it i mean). Quote
Manila Wolf Posted March 13, 2012 Author Posted March 13, 2012 wow.. you lost me there... that is all greek to me ManilaWolf At any rate.. I cant tell what part of that macro stalls when you pass the "p" argument, but I doubt that its within offins routine. unless you indeed have 1067 blocks on your drawing. The code uses a filter for blocks. Besides i cant quite put my finger on these lines _e;all;oops; and E !ss1;;oops (the logic behind it i mean). Hahaha. This what happens when someone like me, who has no idea about lisps, gets a result by going the long long long way round. I get a lot of help from this forum, but I do try and get a result on my own. My own Macro's make me laugh at myself sometimes. In my example, when I called up the offins lisp by the "p" method, AutoCAD attempts to select all the blocks that were originally found by the offins lisp. There were indeed 1067 blocks in my drawing. _e;all;oops; This erases everything in the drawing and then "un-erases" everything. hahahaha. The next lisp in the macro "attaglay" selects all blocks with a particular attribute tag present and makes layers based on the tag name. I select all objects in the drawing by using the "P" (I did mean to take the _e;all;oops; part out of the macro when I found that the "attaglay" lisp can select all anyway. hahahaha). Incidentally, I got the atttaglay lisp written by you from this thread: - http://www.cadtutor.net/forum/showthread.php?64099-move-blocks-to-other-layer-by-attribute-value E !ss1;;oops; I set the recall object to be called by !ss1. _ai_molc, allows me to pick a block and it sets the current layer to match the layer the block is on. I call the object with !ss1. I erase then un-erase the recalled selection, then I can use "p" for offins to select. hahaha. Offins can not select by using the recalled !ss1. If I don't use this erase then un-erase step, offins selects all the tags not just the tag I selected with -ai_molc. hahahaha. Clear as mud. Right? :lol: Quote
pBe Posted March 13, 2012 Posted March 13, 2012 I'm not really familiar with macros to be honest. I can see that with this line (setq ss1 (ssget)) you are prompted to select object, do you supply "p" or another set of objects selected on screen? Quote
Manila Wolf Posted March 13, 2012 Author Posted March 13, 2012 In the macro, (setq ss1 (ssget)) is the first instance asking me to select an object manually. Prior to that everything works automatically without asking me to select anything. So I manually select the object at this point. It is stored as SS1. When the macro prompts to select by the command _ai_molc, the macro calls up the stored selection automatically. It then recalls the stored selection, erases and un-erases it. Now offins can call up the selection as the previous erased and un-erased object rather than the stored SS1 object. Quote
Lee Mac Posted March 13, 2012 Posted March 13, 2012 I call up David's "Offins" lisp in a toolbutton macro selecting the lisp by use of AutoCAD's select previous feature after selecting a block to make the block layer current. This indeed does work, unless I have hundreds of blocks in the drawing. AutoCAD throws up the statement: - Select objects: p 1067 found Select objects: USER INPUT IS TOO LONG. Do you receive any problems when using my code in place of David's? My code doesn't use a command call, which may be causing problems since David's code is supplying the Layer command with a number of layers equal to the number of items in the Selection Set (potentially 1000's), since duplicate layer entries are not being removed. Quote
David Bethel Posted March 13, 2012 Posted March 13, 2012 In the macro, ... Try the updated code in post #3. I must admit, you have lost me on the logic of the macro you have there. -David Quote
Manila Wolf Posted March 15, 2012 Author Posted March 15, 2012 David, Many thanks for your revised code. It works well now. In my example drawing, the original code was selecting all 1067 blocks when running within the macro. (As Lee and you had correctly identified as being the problem). This apparently was too much for AutoCAD to handle. With the new code it now only selects the one block, so it runs without problem. Sincere thanks again for your revised code. Lee, Both your code and David's revised code do indeed work very well if they are used as a single command and not in the middle of a chain of commands. The reason I am employing David's code in my macro is that I can call up David's code within the macro by using AutoCAD's select previous feature. I can now run a string of commands with just one click of a tool button and the "offins" code, buried in the middle of the macro works as I had hoped. I know you guys have the ability to write a single lisp that will run a chain of commands with one hit, but I am not au fait with lisp, so I arrive at what I want by means of a crazy macro. Thanks to all again for helping me. 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.