View Full Version : ssget selecting everything on a layer
3D Jack
2009-04-02, 10:13 PM
I have tried way to long to get the below to work by walking through the layer table and then selecting entities that are on a layer whose color is 251. In the watch window I can see the color and the layer name but it never selects anything. The var SS is always nil. I have tried the ssget filter in different ways but I have given up. I search AUGI and Discussion groups and still no luck. It has to be something simple but I can't see it. Hopefully somebody will see the little error. I am attaching a small drawing file that I have been using for testing in case anyone wants to test for themselves. Thanks a bunch, Jack.
(vl-load-com)
(defun c:jf (/ acadobject activedocument LayerTable thelist)
(command "-layer" "m" "background" "c" "6" "background" "" "") ;_ end command
(setq acadobject (vlax-get-Acad-Object))
(setq activedocument (vla-get-activedocument acadobject))
(setq LayerTable (vla-get-layers activedocument))
(vlax-for each LayerTable
(setq klay_name (vla-get-name each))
(setq clc (vla-get-color each))
(if (= clc "251")
(setq ss1 (ssget "X" (list (cons 8 klay_name)))
) ;_ end setq
;;; this variation also fails to select anything
;;; (setq ss (ssget "_X" '((8 . klay_name))))
;;; (command "._CHPROP" ss "" "la" "layer2" "")
) ;_ end if
) ;_ end of vlax-for
(princ "That's All Folks!")
(princ)
)
RobertB
2009-04-02, 11:44 PM
Hint:
(type (vla-Get-Color (vla-Item (vla-Get-Layers (vla-Get-ActiveDocument
(vlax-Get-Acad-Object)))"0")))
Jack, I don't know the vla-commands.
In an old style, if you need to select the objects that are in layers with color 251, test this:
(setq list_of_layers nil)
(setq mylayer (cdadr (tblnext "layer" t)))
(while mylayer
(if (= 251
(cdr (assoc 62 (entget (tblobjname "layer" mylayer))))
)
(setq list_of_layers (append list_of_layers (list mylayer)))
)
(setq mylayer (cdadr (tblnext "layer")))
)
(setq objets (ssadd))
(mapcar '(lambda (x)
(setq list_obj (cons 8 x))
(setq objets_mylayer (ssget "x" (list list_obj)))
(setq index 0)
(repeat (sslength objets_mylayer)
(setq ent (ssname objets_mylayer index))
(setq index (1+ index))
(setq objets (ssadd ent objets))
)
)
list_of_layers
)
The entities you are looking for are named "OBJETS". Example: (vl-cmdf "_move" objets)
irneb
2009-04-03, 09:58 AM
Reasonably simple:
;; First get a list of layers in comma seperated string form
(setq laystr ""
lay (tblnext "LAYER" t)
)
(while lay
(if (= 251 (cdr (assoc 62 lay))) ;Check if layer has 251 colour
(setq laystr (strcat laystr "," (cdr (assoc 2 lay)))) ;Add layer name to string
)
(setq lay (tblnext "LAYER")) ;Get next layer
)
(if (> (strlen laystr) 0) (setq strlen (substr strlen 2)))Now this string should look something like "Layer1,Layer5,Layer6", assuming those layers were set with colour=251. So now to get a selection set of all entities on those layers:
(setq ss (ssget "X" (list (cons 8 laystr))))If you want all entities on those layers, which are also set to colour ByLayer:
(setq ss (ssget "X" (list (cons 8 laystr) '(62 . 256))))And then if you want all entities colour bylayer on those layers or set to colour 251:
(setq ss (ssget "X"
(list
'(-4 . "<OR")
'(-4 . "<AND")
(cons 8 laystr)
'(62 . 256)
'(-4 . ">AND")
'(62 . 251)
'(-4 . ">OR")
)))Untested, but it should work ... hopefully :mrgreen:
ccowgill
2009-04-03, 11:45 AM
this is what I use, granted it is set up for everything that has a continuous linetype, but you should be able to change the 6 to 62 and "CONTINUOUS" to the color number without quotes:
(defun c:2dpolyosnap (/ ss ss2 ss3)
(setq ss3 "")
(while (setq ss (tblnext "LAYER"))
(if (= (strcase (cdr (assoc 6 ss))) "CONTINUOUS")
(setq ss3 (strcat ss3 "," (cdr (assoc 2 ss))))
) ;_ end of if
) ;_ end of while
(tblnext "LAYER" T)
(setq ss3 (vl-string-left-trim "," ss3))
(setq ss2 (ssget "_X" (list '(0 . "POLYLINE") (cons 8 ss3))))
(if (/= ss2 nil)
(command "pedit" "m" ss2 "" "L" "off" "")
) ;_ end of if
) ;_ end of defun
The program is a fix I developed for 2009 because when it first shipped, you couldnt snap to old style polylines that had a continouous linetype if linetype generation was enabled. So this program shut off linetype generation for all continuous polylines. (we only use bylayer linetypes, so there was no need to check for polylines whose linetypes had been modified manually)
RobertB
2009-04-06, 04:00 PM
Hint:
(type (vla-Get-Color (vla-Item (vla-Get-Layers (vla-Get-ActiveDocument
(vlax-Get-Acad-Object)))"0")))It seems everyone missed what the hint was getting at: the type of data is an INT whereas Jack is comparing against a string.
ccowgill
2009-04-06, 05:26 PM
It seems everyone missed what the hint was getting at: the type of data is an INT whereas Jack is comparing against a string.
but you should be able to change the 6 to 62 and "CONTINUOUS" to the color number without quotes:
I somewhat got it.
RobertB
2009-04-06, 06:02 PM
I somewhat got it.Sorry, I didn't see the OP's code in your reply, so I didn't examine it closely.
ccowgill
2009-04-06, 07:04 PM
Sorry, I didn't see the OP's code in your reply, so I didn't examine it closely.
thats alright, I also must apologize, I really didnt look at the OP's code, I just posted a solution that I had that has worked for me in the past.
3D Jack
2009-04-06, 07:54 PM
A whole bunch of thanks to everyone who replied and the real problem was caused by my not doing a simple checking on variable types. I had the program looking for color "251" which is text instead of 251 as an integer. Had I done that I would not have had to post but I am glad that I did. I am pasting in what I came up with that works really good and want to share with AUGI. If someone knows the VL-commands enough to change the CHPROP section to work faster with VL commands that would be great. Thanks again to everyone. PS: I just noticed a bunch of additional post and I was unsubscibed to this post which I had subscribed to and would want to remain subscribed to. Not sure what happened there but thanks again to everyone.
(vl-load-com)
;;;changes entities from layer whose color is 251 to specified layer
(defun c:ElecChngLayByColor (/ acadobject activedocument LayerTable thelist clc klay_name)
;;;Creates a layer for entities to be moved to
(command "-layer" "m" "background" "c" "6" "background" "") ;_ end command
(setq acadobject (vlax-get-Acad-Object))
(setq activedocument (vla-get-activedocument acadobject))
(setq LayerTable (vla-get-layers activedocument))
(vlax-for each LayerTable
(setq klay_name (vla-get-name each))
(setq clc (vla-get-color each))
;;;above is VL stuff I don't fully understand but it walks through
;;;layer table and gets the color assigned to each layer
;;;if the color is 251 then the "(progn" section runs
(if (= clc 251)
(progn
(setq ss1 (ssget "X" (list (cons 8 klay_name))))
(command "._CHPROP" ss1 "" "la" "BACKGROUND" "c" "bylayer" "")
) ;_ end progn
) ;_ end if
) ;_ end of vlax-for
(princ "That's All Folks!")
(princ)
);defun
RobertB
2009-04-06, 09:15 PM
... If someone knows the VL-commands enough to change the CHPROP section to work faster with VL commands that would be great.
(vl-load-com)
;;;changes entities from layer whose color is 251 to specified layer
(defun c:ElecChngLayByColor (/ acadobject activedocument LayerTable thelist clc klay_name i aObj)
;;;Creates a layer for entities to be moved to
(command "-layer" "m" "background" "c" "6" "background" "") ;_ end command
(setq acadobject (vlax-get-Acad-Object))
(setq activedocument (vla-get-activedocument acadobject))
(setq LayerTable (vla-get-layers activedocument))
(vlax-for each LayerTable
(setq klay_name (vla-get-name each))
(setq clc (vla-get-color each))
;;;above is VL stuff I don't fully understand but it walks through
;;;layer table and gets the color assigned to each layer
;;;if the color is 251 then the "(cond" section runs
(if (= clc 251)
(cond ((setq ss1 (ssget "X" (list (cons 8 klay_name))))
(repeat (setq i (sslength ss1))
(setq aObj (vlax-EName->vla-Object (ssname ss1 (setq i (1- i)))))
(vla-Put-Layer aObj "Background")
(vla-Put-Color aObj acByLayer))))
) ;_ end if
) ;_ end of vlax-for
(princ "That's All Folks!")
(princ)
);defun
3D Jack
2009-04-06, 11:02 PM
Thank you Robert that is definitely faster. However; with our user's and the drawings we are working with I may stay with CHPROP and here is why. My test drawing has 43,000+ entities in it on 500+ different layers. With the CHPROP running each time a layer is changed you see the color change to the screen so you know the program has not locked up. We are looking at 30 seconds plus for this to run. With past network problems we had unbelieveable lags that would take 30 seconds to draw a line. Everyone is so used to that and all the lockups they will think this is a lockup when it is actually still running. Your post is definitely the better of the two and I may just let the user's decide which they prefer. Much appreciated, Jack.
RobertB
2009-04-07, 12:03 AM
You could add a spinner (http://forums.augi.com/showpost.php?p=759483&postcount=2) to let them know it is still working.
3D Jack
2009-04-07, 03:05 PM
I thought about adding a spinner but I just did a time comparison and they were nearly the same, about 26 seconds to do everything. The savings isn't enough to justify the spinner and it is kind of cool to watch things all over the screen change their colors to the new bylayer color of the layer they are placed on. Thanks again to everyone for all the help and also hoping somebody can copy and modify to create some other program.
irneb
2009-06-17, 09:42 AM
(vlax-for each LayerTable
;; ........
(if (= clc 251)
(cond ((setq ss1 (ssget "X" (list (cons 8 klay_name))))
;; ........
) ;_ end if
) ;_ end of vlax-for
That could get dangerous ... you are only allowed 128 active selection sets. As per Robert & my posts in this thread (http://forums.augi.com/showthread.php?t=102333). You'll need a (setq ss1 nil) and a (gc) just after the end of the repeat loop.
Otherwise if there's more than 128 layers, you could get an error. The gc should be called to force the release of the selection set from RAM ... otherwise Lisp waits for some idle time to release it (which may only happen once the code completes).
RobertB
2009-06-17, 07:22 PM
That could get dangerous ... you are only allowed 128 active selection sets. As per Robert & my posts in this thread (http://forums.augi.com/showthread.php?t=102333). You'll need a (setq ss1 nil) and a (gc) just after the end of the repeat loop.Good point, and an ironic cross posting eh? ;)
irneb
2009-06-18, 04:41 AM
It never rains, but it pours doesn't it? :twisted:
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.