Jump to content

Select objects in current layer


3dwannab

Recommended Posts

(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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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                              ;;
;;----------------------------------------------------------------------;;

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 years later...

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)
)

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...