Problem with selection set

Problem with selection set

oli-123
Contributor Contributor
1,107 Views
5 Replies
Message 1 of 6

Problem with selection set

oli-123
Contributor
Contributor

 

Hello, I'm new to AutoLISP so I'm sure I'll be making a lot of mistakes. However, the one problem that stumps me is this function. I have some blocks on a layout; some of the blocks are named "dsm" under layer "G-NOTES". So if I want to use selection set function to highlight all the blocks in that layout with those specific properties, I made a function like this:

 

(setq ss1
		(ssget "x" '((2 . "dsm")(8 . "G-NOTES")))
)

The problem is that when I hit F2, the command line states that the selection set is f86. And I was thinking "What???" I'm expecting a number, not a mix of number and a letter. (And I do not have 86 blocks like that)

 

What can be a problem here? Thanks!

 

0 Likes
Accepted solutions (2)
1,108 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@oli-123 wrote:

 

.... when I hit F2, the command line states that the selection set is f86. And I was thinking "What???" I'm expecting a number, not a mix of number and a letter. ....


That's just a selection-set identifier, which you don't need to concern yourself with [it's probably a hexadecimal number].  Since you have set that into your ss1 variable, you can find out how many such Blocks it it found with:

 

(sslength ss1)

 

If you want it to highlight/select/grip them, so you can see where they are, etc., you can do:

 

(sssetfirst nil ss1)

Kent Cooper, AIA
0 Likes
Message 3 of 6

SeeMSixty7
Advisor
Advisor
Accepted solution

Since it sounds like you want to limit your selection set to the current Layout you may want to consider the following code. This will limit your selection to the current layout or model space. I added the INSERT specifier as well, as you could get entities you don't want (like any attdefs on the same layer), and I believe it would actually process faster for you. I believe the specifying the entity type first limits the remaining specifiers down even farther. I have not actually tested that, but my logic has always been with that belief.

 

Good luck,

 

 

(setq ss1 (ssget "x" (list (cons 0 "INSERT")
                                      (cons 2 "dsm")
                                      (cons 8 "G-NOTES")
                                       (cons 410 (getvar "CTAB"))
                                )
                 )
)

  

0 Likes
Message 4 of 6

oli-123
Contributor
Contributor

@Kent1Cooper wrote:

That's just a selection-set identifier, which you don't need to concern yourself with [it's probably a hexadecimal number].  Since you have set that into your ss1 variable, you can find out how many such Blocks it it found with:

(sslength ss1)


I should have known that earlier. I really wish there's a good way to find a bug in my code!

 

 


SeeMSixty7 wrote:

Since it sounds like you want to limit your selection set to the current Layout you may want to consider the following code. This will limit your selection to the current layout or model space. I added the INSERT specifier as well, as you could get entities you don't want (like any attdefs on the same layer), and I believe it would actually process faster for you. I believe the specifying the entity type first limits the remaining specifiers down even farther. I have not actually tested that, but my logic has always been with that belief.


That's really useful. Being a new user, seeing new functions like (cons 410) is looks confusing. But thanks!

0 Likes
Message 5 of 6

SeeMSixty7
Advisor
Advisor

Cons constructs a dotted pair, basically a dxf code item. So if you wanted to build (0 . "INSERT") you can use (cons 0 "INSERT) 

 

'(0 . "INSERT") woudl result in the same things, but behind the quote nothing is evaluated. Since you wanted to use the current layout, we need to evaluate what (getvar "CTAB") returned. That is why with built the list with functions instead of a quoted statement that is not evaluated.

 

Hope that helps.

 

 

0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant

@SeeMSixty7 wrote:

... built the list with functions instead of a quoted statement that is not evaluated.

.... 


You can combine them.  That construction can be shortened somewhat by using quoted [read literally, unevaluated] lists [in this case dotted pairs] for the elements that have known/fixed content, and a (cons) function only for the one(s) with content that might vary:

 

(setq ss1

  (ssget "_X"

    (list

      '(0 . "INSERT")
      '(2 . "dsm")
      '(8 . "G-NOTES")
      (cons 410 (getvar 'ctab))
    )
  )
)

 

But note that you have to individually quote each of those entries that's not a (cons) function, and you can't quote the overall filter list but need to build it with an explicit (list) function, since it does contain something requiring evaluation, even if a lot of what's in it does not.

Kent Cooper, AIA
0 Likes