View Full Version : Problem with Selection Set
airick01
2009-03-27, 12:46 AM
I am new to writing lisp, so I can't figure out what I'm doing wrong.
Using this lisp, the layers in my drawing ('layer1', 'layer3', 'layer5') are all going to 'layer6'.
My goal is to have 'layer1' turn to 'layer2', 'layer 3' turn to 'layer4' and 'layer 5' turn to 'layer 6'.
I'm sure the solution is rather simple, but being new to this stuff, my attempts have failed.
Any help is appreciated!
Terry Cadd
2009-03-27, 01:27 AM
Hi airick01,
You were close, but just missed a few things.
Put a "/" before your local variable 'ss'. i.e. (defun c:switchlayers (/ ss).
Also change the lines like (if ss '((8 . "layer5"))) to (if (setq ss (ssget "_X" '((8 . "layer5"))))
Other than that, you got it.
(defun c:switchlayers (/ ss)
(if (tblsearch "LAYER" "layer1")
(progn
(if (not (tblsearch "LAYER" "layer2"))
(progn
(command "._LAYER" "_MAKE" "layer2" "_C" "4" "" "_L" "CONTINUOUS" "" "" )
(princ "\n Layer layer2 has been made.")
)
)
(if (setq ss (ssget "_X" '((8 . "layer1"))))
(command "._CHPROP" ss "" "la" "layer2" "")
)
)
)
(if (tblsearch "LAYER" "layer3")
(progn
(if (not (tblsearch "LAYER" "layer4"))
(progn
(command "._LAYER" "_MAKE" "layer4" "_C" "4" "" "_L" "CONTINUOUS" "" "" )
(princ "\n Layer layer4 has been made.")
)
)
(if (setq ss (ssget "_X" '((8 . "layer3"))))
(command "._CHPROP" ss "" "la" "layer4" "")
)
)
)
(if (tblsearch "LAYER" "layer5")
(progn
(if (not (tblsearch "LAYER" "layer6"))
(progn
(command "._LAYER" "_MAKE" "layer6" "_C" "4" "" "_L" "CONTINUOUS" "" "" )
(princ "\n Layer layer6 has been made.")
)
)
(if (setq ss (ssget "_X" '((8 . "layer5"))))
(command "._CHPROP" ss "" "la" "layer6" "")
)
)
)
(princ)
);end lisp
airick01
2009-03-27, 02:10 AM
Hi thanks for your help.
I used the code you posted, which worked like I want, but it did not prompt me to select objects. It took all the layers in my drawing (1,3,5) and turned them to (2,4,6) but without selecting them. I pasted back in the code: (setq ss nil) (setq ss (ssget)) which was removed. This prompted me to select objects (which I want), but still it changed ALL layers (1,3,5) to the new layer (2,4,6) even if I didn't select them. Is there a way to change ONLY the selected layers?
Terry Cadd
2009-03-27, 03:02 PM
Like this?
(defun c:switchlayers (/ ss)
(if (tblsearch "LAYER" "layer1")
(progn
(if (not (tblsearch "LAYER" "layer2"))
(progn
(command "._LAYER" "_MAKE" "layer2" "_C" "4" "" "_L" "CONTINUOUS" "" "" )
(princ "\n Layer layer2 has been made.")
)
)
(princ "\n Select objects on layer1 to change to layer2. ")
(if (setq ss (ssget '((8 . "layer1"))))
(command "._CHPROP" ss "" "la" "layer2" "")
)
)
)
(if (tblsearch "LAYER" "layer3")
(progn
(if (not (tblsearch "LAYER" "layer4"))
(progn
(command "._LAYER" "_MAKE" "layer4" "_C" "4" "" "_L" "CONTINUOUS" "" "" )
(princ "\n Layer layer4 has been made.")
)
)
(princ "\n Select objects on layer3 to change to layer4. ")
(if (setq ss (ssget '((8 . "layer3"))))
(command "._CHPROP" ss "" "la" "layer4" "")
)
)
)
(if (tblsearch "LAYER" "layer5")
(progn
(if (not (tblsearch "LAYER" "layer6"))
(progn
(command "._LAYER" "_MAKE" "layer6" "_C" "4" "" "_L" "CONTINUOUS" "" "" )
(princ "\n Layer layer6 has been made.")
)
)
(princ "\n Select objects on layer5 to change to layer6. ")
(if (setq ss (ssget '((8 . "layer5"))))
(command "._CHPROP" ss "" "la" "layer6" "")
)
)
)
(princ)
);end lisp
airick01
2009-03-27, 04:30 PM
Terry Cadd....
This is REALLY close. Works just as I hoped, with 1 exception. What I haven't mentioned yet, is that I plan on taking code this and applying it to about 70-80 company standard layers. Copying each segment (layer1 to layer2) about 75 times. Using this method, it would prompt me 75 times on 1 command. It's functional, but not ideal.
Is there a way to have this only ask once for a selection set?
Terry Cadd
2009-03-27, 05:15 PM
Hi,
Do you mean something like this?
(defun c:switchlayers (/ ss ss-layername ss-temp)
(defun ss-layername (ss layername / cnt entitylist entityname layer new-ss)
(setq new-ss (ssadd))
(setq cnt 0)
(repeat (sslength ss)
(setq entitylist (entget (ssname ss cnt)))
(setq entityname (cdr (assoc -1 entitylist)))
(setq layer (cdr (assoc 8 entitylist)))
(if (= layer layername)
(ssadd entityname new-ss)
)
(setq cnt (1+ cnt))
)
(if (> (sslength new-ss) 0)
new-ss
)
)
(princ "\n Select objects to switch layers. ")
(if (not (setq ss (ssget)))
(exit)
)
(if (tblsearch "LAYER" "layer1")
(progn
(if (not (tblsearch "LAYER" "layer2"))
(progn
(command "._LAYER" "_MAKE" "layer2" "_C" "4" "" "_L" "CONTINUOUS" "" "" )
(princ "\n Layer layer2 has been made.")
)
)
(if (setq ss-temp (ss-layername ss "layer1"))
(command "._CHPROP" ss-temp "" "la" "layer2" "")
)
)
)
(if (tblsearch "LAYER" "layer3")
(progn
(if (not (tblsearch "LAYER" "layer4"))
(progn
(command "._LAYER" "_MAKE" "layer4" "_C" "4" "" "_L" "CONTINUOUS" "" "" )
(princ "\n Layer layer4 has been made.")
)
)
(if (setq ss-temp (ss-layername ss "layer3"))
(command "._CHPROP" ss-temp "" "la" "layer4" "")
)
)
)
(if (tblsearch "LAYER" "layer5")
(progn
(if (not (tblsearch "LAYER" "layer6"))
(progn
(command "._LAYER" "_MAKE" "layer6" "_C" "4" "" "_L" "CONTINUOUS" "" "" )
(princ "\n Layer layer6 has been made.")
)
)
(if (setq ss-temp (ss-layername ss "layer5"))
(command "._CHPROP" ss-temp "" "la" "layer6" "")
)
)
)
(princ)
);end lisp
airick01
2009-03-27, 08:31 PM
Well it created the layers, and only asked for 1 selection, but other than that nothing happened. Layers 1,3,5 did not switch to 2,4,6.
Attached is an older attempt at this lisp that I made (with help). I also renamed the file to N2E (or New to Existing) because that ultimately I'm trying to achieve. Take New (selected) layers and change them to Existing.
It works just as I want, but forces me to use a 2 point window, only selecting everything inside the window. Any ideas on how to alter this to use a (ssget) selection style instead of the (ssget "w")?
Terry Cadd
2009-03-31, 01:56 AM
Hi airick01,
From the looks of your N2E function, it works similar to the last function I posted.
Lets say that you have 5 objects on layer1 and you only select 2 objects.
Only those 2 objects will be moved to layer2 and the other 3 will remain on layer1.
Do you want all of the objects on layer1 to be moved to layer2, if 1 or more objects on layer1 are selected?
airick01
2009-03-31, 07:45 PM
Hello, nevermind my last post. I think I had been staring at my computer screen to long last week. I tried that last lisp you posted again, with fantastic results. Works just perfectly. I was getting errors last week, but to my own fault substituting my company's layers in. Just needed the weekend to clear my head.
Thankyou for all your help!!
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.