Jump to content
3dwannab

Select objects in current layer

Recommended Posts

3dwannab

(sssetfirst nil (ssget "_X" '((8 . "5"))))

will select objects in layer 5 no problem but when i incorporate

(getvar "CLAYER")

to make:

(sssetfirst nil (ssget "_X" '((8 . (getvar "CLAYER")))))

It comes back with error: ; error: bad SSGET list value

 

It's probably just a simple fix (heck, maybe even a standard command to do the same)

 

Thanks in advance.

Share this post


Link to post
Share on other sites
3dwannab
mAC;633024]See if you can work out why from my tutorial The Apostrophe and the Quote Function ;)

Sorry, maybe having a slow day but I can't get that to work. Have tried which seems like the most logical solution:

(setq ss (getvar "CLAYER"))
(sssetfirst nil (ssget "_X" '((8 . (list ss)))))

from this example:

_$ (setq x 5)
5
_$ (list 1 2 3 4 x)
(1 2 3 4 5)

I'm learning maxscript also and find it much more user friendly to learn.

Share this post


Link to post
Share on other sites
Lee Mac

Refer to the ssget example in this section - remember that any expression following a quote/apostrophe will not be evaluated.

Share this post


Link to post
Share on other sites
3dwannab
Refer to the ssget example in this section - remember that any expression following a quote/apostrophe will not be evaluated.

Thanks. Maybe my brain isin't all there today but looking at your example didn't help. I still know you're the LISP master :)

 

I found this link here in the help: http://exchange.autodesk.com/autocad/enu/online-help/browse#WS73099cc142f4875516d84be10ebc87a53f-7a31.htm

 

I've came up with three variations which do the same thing :shock:

 

(setq lay_name (getvar "CLAYER"))
(setq ss1 (ssget "_X" (list (cons 8 lay_name))))
(command "pselect" "P" "")

------------------------------------

(setq ss1 (ssget "_X" (list (cons 8 (getvar "CLAYER")))))
(command "pselect" ss1 "")

------------------------------------

(ssget "_X" (list (cons 8 (getvar "CLAYER"))))
(command "pselect" "P" "")

 

Thanks for your help.

Share this post


Link to post
Share on other sites
tombu
Thanks. Maybe my brain isin't all there today but looking at your example didn't help. I still know you're the LISP master :)

 

I found this link here in the help: http://exchange.autodesk.com/autocad/enu/online-help/browse#WS73099cc142f4875516d84be10ebc87a53f-7a31.htm

 

I've came up with three variations which do the same thing :shock:

 

(setq lay_name (getvar "CLAYER"))
(setq ss1 (ssget "_X" (list (cons 8 lay_name))))
(command "pselect" "P" "")

------------------------------------

(setq ss1 (ssget "_X" (list (cons 8 (getvar "CLAYER")))))
(command "pselect" ss1 "")

------------------------------------

(ssget "_X" (list (cons 8 (getvar "CLAYER"))))
(command "pselect" "P" "")

 

Thanks for your help.

 

Glad you found a solution, but Lee's link explains the quote function as well as any I've seen. Do you understand now that the difference between using quote -vs- the list and cons functions is that any expression following a quote/apostrophe will not be evaluated?

Share this post


Link to post
Share on other sites
3dwannab

I do to some degree it will sink in eventually. I don't know want has happened but NONE of the examples I had working are working now. Commandline is now saying "Unknown command "PSELECT". Press F1 for help." All those were working perfectly beforehand.

 

My lisp so far.

(defun c:SEL_LAYER_CURRENT ( / cmdecho )
   (setq  cmdecho (getvar 'cmdecho))
   (setvar 'cmdecho 0)

   (setq ss1 (ssget "_X" (list (cons 8 (getvar "CLAYER")))))
   (command "pselect" ss1 "")
   ;;(princ (strcat "\n" (sslength ss1) " objects selected. "))

    
   ;;(print (sslength ss1))

   (setvar 'cmdecho cmdecho)
)

I also want to print the amount of selected objects after the command has finished but I having trouble joining up the text string and the amount of objects.

Share this post


Link to post
Share on other sites
Tharwat

Eg.

 

(defun c:Test (/ s)
 (if (setq s (ssget "_X" (list (cons 8 (getvar "CLAYER")))))
   (princ (strcat "\nNumber of Found objects : < " (itoa (sslength s)) " >"))
 )
 (sssetfirst nil s)
 (princ)
)

Share this post


Link to post
Share on other sites
3dwannab
Eg.

 

(defun c:Test (/ s)
 (if (setq s (ssget "_X" (list (cons 8 (getvar "CLAYER")))))
   (princ (strcat "\nNumber of Found objects : < " (itoa (sslength s)) " >"))
 )
 (sssetfirst nil s)
 (princ)
)

Excellent Tharwat. I understand fully what all that code does. (I thought I tried itoa to convet it to a string!!) Thanks very much. I think this simple routine will take over the LAYWALK command for me. BTW it could be useful of it allowed the user to have the dialog open. Anyway this is great. Here's the code.

 

;;---------------=={ 3DwannaB_Sel_Layer_Current.lsp }==-----------------;;
;;                                                                      ;;
;;  Selects All Objects On Current Later                                ;;
;;----------------------------------------------------------------------;;
;;  Author: 3DwannaB, Copyright © 2015                                  ;;
;;----------------------------------------------------------------------;;
;;  Version 1.0    -    23-05-2015                                      ;;
;;                                                                      ;;
;;  First Release. Lots of help from 'Lee Mac' Credit goes to 'Tharwat' ;;
;;  See http://bit.ly/1HzZrlM                                             ;;
;;                                                                      ;;
;;----------------------------------------------------------------------;;

(defun c:SEL_LAYER_CURRENT (/ s cmdecho )
   (setq  cmdecho (getvar 'cmdecho))
   (setvar 'cmdecho 0)
       (if (setq s (ssget "_X" (list (cons 8 (getvar "CLAYER")))))
       (princ (strcat "\nNumber of Found objects : < " (itoa (sslength s)) " >"))
   )
   (sssetfirst nil s)
   (setvar 'cmdecho cmdecho)
   (princ)
)
;;----------------------------------------------------------------------;;
(princ
   (strcat
       "\n:: 3DwannaB_Sel_Layer_Current.lsp | Version 1.0 | by 3DwannaB  ::"
       "\n:: Type \"Sel_Layer_Current\" to Invoke                          ::"
   )
)
(princ)
;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;

Share this post


Link to post
Share on other sites
Tharwat
Excellent Tharwat. I understand fully what all that code does. (I thought I tried itoa to convet it to a string!!) Thanks very much. I think this simple routine will take over the LAYWALK command for me. BTW it could be useful of it allowed the user to have the dialog open. Anyway this is great. Here's the code.

 

You are most welcome .

 

Can you tell me what is the need of the System Variable CMDECHO into the routine ?

Share this post


Link to post
Share on other sites
3dwannab

I suppose it doesn't really have much use here. Force of habit putting it in there I suppose. Would it also be difficult to get this to search block tables to the current layer and select the block. Would be very useful for cleaning up drawings. I know I have the LAYTRANS command but sometimes manual is the only way sometimes.

Share this post


Link to post
Share on other sites
Lee Mac
Glad you found a solution, but Lee's link explains the quote function as well as any I've seen.

 

Thank you tombu :thumbsup:

Share this post


Link to post
Share on other sites
3dwannab

Hi,

 

Why would this fail if the layers name is:

ConstructionArrayLine [DO NOT DELETE]

 

 

(defun c:QS_LAYER_CURRENT (/ ss_1 )
(if
	(setq ss_1 (ssget "_X" (list (cons 8 (getvar "CLAYER")))))
	(princ (strcat "\nNumber of found objects : < " (itoa (sslength ss_1)) " >"))
	)
(sssetfirst nil ss_1)
(command "._regenall")
(princ)
)

Share this post


Link to post
Share on other sites
ronjonp

It's because the name uses brackets. Try ConstructionArrayLine `[DO NOT DELETE`]

Share this post


Link to post
Share on other sites
Lee Mac

You need to escape the wildcard operators present in the layer name (in this case, the square brackets "[" & "]").

 

For this, you can use my Escape Wildcards function:

(defun c:qs_layer_current ( / s )
   (if (setq s (ssget "_X" (list (cons 8 (LM:escapewildcards (getvar 'clayer))) (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model")))))
       (princ (strcat "\nFound " (itoa (sslength s)) " object" (if (= 1 (sslength s)) "." "s.")))
       (princ "\nNo objects found.")
   )
   (sssetfirst nil s)
   (command "._regenall")
   (princ)
)

Share this post


Link to post
Share on other sites
3dwannab
You need to escape the wildcard operators present in the layer name (in this case, the square brackets "[" & "]").

 

I actually looked at your ssget examples Lee to see if there was anything about special characters. Maybe it was there but I missed it.

 

Thank you and thanks for your great functions.

Share this post


Link to post
Share on other sites
tombu
You need to escape the wildcard operators present in the layer name (in this case, the square brackets "[" & "]").

 

For this, you can use my Escape Wildcards function:

 

Worked great, I added it to my modified SSX.lsp so it would work as well. After searching all my code for "(assoc 8" and found 186 occurrence(s) in 95 files I decided it's best not to ever use any wildcard operators in our layer names. It's worked for us so far.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×