bono05 Posted August 12, 2011 Share Posted August 12, 2011 Hello, My problem is that i need to put all layers to color 8 (for this no problem). But after this i need to set only one layer back to Bylayer. My idea is to have a lisp where i can set his name (not by click or selection). I hope can someone help me. Thanks! Quote Link to comment Share on other sites More sharing options...
pBe Posted August 12, 2011 Share Posted August 12, 2011 (edited) (defun BackToBYLayer (Lay) (if (and (tblsearch "LAYER" Lay) (ssget "_X" (list (cons 8 Lay)))) (command "_Chprop" "P" "" "Color" "Bylayer" "") )(princ) ) USAGE: (BackToBYLayer "LayerName") Edited August 12, 2011 by pBe Quote Link to comment Share on other sites More sharing options...
irneb Posted August 13, 2011 Share Posted August 13, 2011 Or perhaps this one to work with entities inside blocks as well: (vl-load-com) (defun BackToByLayer2 (name / blk eo) (vlax-for blk (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for eo blk (if (eq (strcase name) (strcase (vla-get-Layer eo))) (vl-catch-all-apply 'vla-put-Color (list eo 256)) ) ) ) ) Quote Link to comment Share on other sites More sharing options...
pBe Posted August 13, 2011 Share Posted August 13, 2011 Or perhaps this one to work with entities inside blocks as well:(vl-load-com) (defun BackToByLayer2 (name / blk eo) (vlax-for blk (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for eo blk (if (eq (strcase name) (strcase (vla-get-Layer eo))) (vl-catch-all-apply 'vla-put-Color (list eo 256)) ) ) ) ) I see you notice the how first code behaves with Blocks too Irneb... Good one Quote Link to comment Share on other sites More sharing options...
irneb Posted August 13, 2011 Share Posted August 13, 2011 I see you notice the how first code behaves with Blocks too Irneb... Good one Yep, I've learned that a while back on AUGI. But it's always a good idea to share Quote Link to comment Share on other sites More sharing options...
bono05 Posted August 16, 2011 Author Share Posted August 16, 2011 (defun BackToBYLayer (Lay) (if (and (tblsearch "LAYER" Lay) (ssget "_X" (list (cons 8 Lay)))) (command "_Chprop" "P" "" "Color" "Bylayer" "") )(princ) ) USAGE: (BackToBYLayer "LayerName") Hello, Back from a long Week-end... So i tried your code but what's de command? Because "backtobylayer" doesn't working with me? Many thanks. Quote Link to comment Share on other sites More sharing options...
pBe Posted August 16, 2011 Share Posted August 16, 2011 First: (BackToBYLayer "LayerName"); Second: use Irnebs code. it works well even with blocks (BackToByLayer2 "LayerName") Cheers Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 16, 2011 Share Posted August 16, 2011 Put the following code into your command line and hit enter and when it selects entities make it manually Bylayer. (sssetfirst nil (ssget "_x" '((62 . ))) Tharwat Quote Link to comment Share on other sites More sharing options...
pBe Posted August 16, 2011 Share Posted August 16, 2011 with that snippet, you need to isolate the the specific layers first before doing that Tharwat Hence the 'Layername" argument (but nevertheless a useful bit) Quote Link to comment Share on other sites More sharing options...
bono05 Posted August 16, 2011 Author Share Posted August 16, 2011 First:(BackToBYLayer "LayerName"); Second: use Irnebs code. it works well even with blocks (BackToByLayer2 "LayerName") Sorry but this is the result: Command: (BackToBYLayer "A-_0041--_T-_N_NUMEROS DES LOCAUX NOUVEAU") ; error: AutoCAD rejected function: invalid table function argument(s): "A-_0041--_T-_N_NUMEROS DES LOCAUX NOUVEAU" "A-_0041--_T-_N_NUMEROS DES LOCAUX NOUVEAU" Quote Link to comment Share on other sites More sharing options...
bono05 Posted August 16, 2011 Author Share Posted August 16, 2011 Put the following code into your command line and hit enter and when it selects entities make it manually Bylayer. (sssetfirst nil (ssget "_x" '((62 . ))) Tharwat And result for this one: Command: (sssetfirst nil (ssget "_x" '((62 . ))) (nil ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 16, 2011 Share Posted August 16, 2011 And result for this one: Command: (sssetfirst nil (ssget "_x" '((62 . ))) (nil ) Yes , then what ? Quote Link to comment Share on other sites More sharing options...
irneb Posted August 16, 2011 Share Posted August 16, 2011 Tharwat, I think you misunderstood the idea: The OP wanted to change everything on a particular layer to be ByLayer, he's already set that layer's colour to 8. Your idea is quite good otherwise, it also shows a way of using wildcard matching so the user need not enter the entire layername. In bobo's example he could've entered only A-_0041* to get all layers starting with A-_0041 in their name. So here's how I'd do it: (defun SelectByLayer (name /) (sssetfirst nil (ssget "_x" (list (cons 8 "LayerName")))) ) (defun c:SelectByLayer (/ LName) (if (setq LName (getstring t "Type the layer's name (or wildcard) to select: ")) (progn (SelectByLayer LName) (prompt (strcat "All entities on layer \"" LName "\" has been selected.")) ) ) (princ) ) (defun c:BackToLayer2 (/ LName) (if (setq LName (getstring t "Type the layer's name (or wildcard) of which to set to ByLayer: ")) (progn (BackToByLayer2 LName) (prompt (strcat "All entities (even nested in blocks) on layer \"" LName "\" has been set to color ByLayer." ) ) ) ) (princ) ) (defun BackToByLayer2 (name / blk eo) (setq name (strcase name)) (vlax-for blk (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for eo blk (if (wcmatch (strcase (vla-get-Layer eo)) name) (vl-catch-all-apply 'vla-put-Color (list eo 256)) ) ) ) ) Note the c: functions define commands to call the normal functions after asking the user to type in the name. Quote Link to comment Share on other sites More sharing options...
bono05 Posted August 17, 2011 Author Share Posted August 17, 2011 Tharwat, I think you misunderstood the idea: The OP wanted to change everything on a particular layer to be ByLayer, he's already set that layer's colour to 8. Your idea is quite good otherwise, it also shows a way of using wildcard matching so the user need not enter the entire layername. In bobo's example he could've entered only A-_0041* to get all layers starting with A-_0041 in their name. So here's how I'd do it: (defun SelectByLayer (name /) (sssetfirst nil (ssget "_x" (list (cons 8 "LayerName")))) ) (defun c:SelectByLayer (/ LName) (if (setq LName (getstring t "Type the layer's name (or wildcard) to select: ")) (progn (SelectByLayer LName) (prompt (strcat "All entities on layer \"" LName "\" has been selected.")) ) ) (princ) ) (defun c:BackToLayer2 (/ LName) (if (setq LName (getstring t "Type the layer's name (or wildcard) of which to set to ByLayer: ")) (progn (BackToByLayer2 LName) (prompt (strcat "All entities (even nested in blocks) on layer \"" LName "\" has been set to color ByLayer." ) ) ) ) (princ) ) (defun BackToByLayer2 (name / blk eo) (setq name (strcase name)) (vlax-for blk (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for eo blk (if (wcmatch (strcase (vla-get-Layer eo)) name) (vl-catch-all-apply 'vla-put-Color (list eo 256)) ) ) ) ) Note the c: functions define commands to call the normal functions after asking the user to type in the name. Great!!! This one working for me. Thanks to all!!!!!! Quote Link to comment Share on other sites More sharing options...
irneb Posted August 17, 2011 Share Posted August 17, 2011 Glad it works for you! Here's a further enhancement: (defun SelectByLayer (name /) (sssetfirst nil (ssget "_x" (list (cons 8 "LayerName")))) ) (defun c:SelectByLayer (/) (if (or (not (eq (setq LName (getstring t "Type the layer's name (or wildcard) to select or <Enter to Select>: ")) "")) (setq LName (PickLayers)) ) (progn (SelectByLayer LName) (prompt (strcat "All entities on layer \"" LName "\" has been selected.")) ) ) (princ) ) (defun PickLayers (/ ss n lay LName) (prompt "\nSelect sample entities on the layers you want. ") (if (setq ss (ssget)) (progn (setq n (sslength ss)) (while (>= (setq n (1- n)) 0) (setq lay (cdr (assoc 8 (entget (ssname ss n))))) (if (not (member lay LName)) (setq LName (cons lay LName)) ) ) (setq lay LName LName "" ) (foreach l lay (setq LName (strcat LName "," l)) ) (setq LName (substr LName 2)) ) ) LName ) (defun c:BackToLayer2 (/ LName) (if (or (not (eq (setq LName (getstring t "Type the layer's name (or wildcard) of which to set to ByLayer or <Enter to Select>: ")) "")) (setq LName (PickLayers)) ) (progn (BackToByLayer2 LName) (prompt (strcat "All entities (even nested in blocks) on layer \"" LName "\" has been set to color ByLayer." ) ) ) ) (princ) ) (defun BackToByLayer2 (name / blk eo) (setq name (strcase name)) (vlax-for blk (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for eo blk (if (wcmatch (strcase (vla-get-Layer eo)) name) (vl-catch-all-apply 'vla-put-Color (list eo 256)) ) ) ) ) Allows you to select some entities on layers instead of typing in each layer name. It should work with multiple layers at once as well. 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.