Jump to content

Help needed with "ssget filter for inserts with specific attribute tags"


MarcoW

Recommended Posts

Hello there,

 

I have googled around for a while but can't find the answer to my problem.

This is the code where it is all about:

 

(setq ss (ssget "_:L"
     (list (cons 0 
"INSERT")
    (cons 66 1)

(cons 410 (getvar "CTAB")))))

 

It basically adds every selected object to the selectionset "ss" as long as it is a block (insert) in the current space. The (cons 66 1) I must admit doesn't ring a bell.

 

My problem is that it should only add blocks to the selectionset that contain 3 ATTRIBUTETAGS. I know / guess that I should first create the selectionset as posted, then cycle through each item and see if it contains TAG1 + TAG2 + TAG3 (all of them). If no then "remove" from selection set.

 

In the end the selectionset will only contain blocks that contain at least the 3 attributetags.

 

But I have no clue, even a wide search did not help. All I can find is how to retrieve the attribute-values. Thats not what I mean, I am after the blocks with 3 specific attributetags.

 

Any help is much appreciated!

Link to comment
Share on other sites

You cannot filter for subentities using a SelectionSet filter with ssget. You will need to make a SelectionSet of all attribute Inserts (perhaps filtering for name as well), and then iterate through this set, removing any blocks which don't match the attribute tag criterion.

 

A quick and crude example:

 

(defun SelectBlockWithTags ( tags / a i e s ) (setq tags (strcase tags))
 
 (if (setq s (ssget "_X" '((0 . "INSERT") (66 . 1))))
   (repeat (setq i (sslength s))
     (setq e (ssname s (setq i (1- i))) a e)
     (while (and a (eq "ATTRIB" (cdr (assoc 0 (entget (setq a (entnext a)))))))
       (if (wcmatch (strcase (cdr (assoc 2 (entget a)))) tags)
         (setq a nil)
       )
     )
     (if a (ssdel e s))
   )
 )
 s
)

Hence to return a SelectionSet of all blocks with Tags: TAG1, TAG2, TAG3:

 

(SelectblockWithTags "TAG[123]")

 

EDIT: Note that the above example will filter for blocks matching any 1 of the three tags, you will need to tweak the filter to get only those blocks with ALL of the three.

Link to comment
Share on other sites

A bit more elementary than Lee's :

 

[b][color=BLACK]([/color][/b]defun findatts [b][color=FUCHSIA]([/color][/b]al / il ss en ed an ad rl tn[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"X"[/color] '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b][b][color=BLUE]([/color][/b]66 . 1[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]setq il [b][color=MAROON]([/color][/b]ssadd[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b]
                   an [b][color=GREEN]([/color][/b]entnext en[b][color=GREEN])[/color][/b]
                   ad [b][color=GREEN]([/color][/b]entget an[b][color=GREEN])[/color][/b]
                   rl nil[b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]= [color=#2f4f4f]"ATTRIB"[/color] [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 0 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]setq tn [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 2 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]and [b][color=BLUE]([/color][/b]member tn al[b][color=BLUE])[/color][/b]
                         [b][color=BLUE]([/color][/b]not [b][color=RED]([/color][/b]member tn rl[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                         [b][color=BLUE]([/color][/b]setq rl [b][color=RED]([/color][/b]cons tn rl[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]setq an [b][color=BLUE]([/color][/b]entnext an[b][color=BLUE])[/color][/b]
                          ad [b][color=BLUE]([/color][/b]entget an[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]if [b][color=GREEN]([/color][/b]= [b][color=BLUE]([/color][/b]length rl[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]length al[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                 [b][color=GREEN]([/color][/b]ssadd en il[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]ssdel en ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
  il[b][color=BLACK])[/color][/b]

 

Syntax:

 


[b][color=BLACK]([/color][/b]findatts '[b][color=FUCHSIA]([/color][/b][color=#2f4f4f]"TAG1"[/color] [color=#2f4f4f]"TAG2"[/color] [color=#2f4f4f]"TAG3"[/color][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

Reminder : All tags are UPPERCASE

 

-David

Link to comment
Share on other sites

@ Lee:

Thanks for this piece of code, it works great, but like you said only for 1 TAG. I could have tried to modify it, but David was too fast. (I would have needed more time to figure it out of course).

 

@ David:

Also many thanks, this works great! It does exactly what I want it to do.

 

 

To be honest: both codes don't look that hard to understand but I have some trouble with it... I must study some functions I don't use like "entnext" etc. Maybe that can clarify things. Too bad: because of a lack of time (almost continuous) I cannot dig in right now so it must wait until then. Thanks again!

Link to comment
Share on other sites

If only the ":V" option actually did work it might have been possible to select the attributes themselves instead of the blocks first.

Link to comment
Share on other sites

If only the ":V" option actually did work it might have been possible to select the attributes themselves instead of the blocks first.

Never give up hope. Autodesk will fix it one day. smiley-rolleyes008.gif

Link to comment
Share on other sites

If only the ":V" option actually did work it might have been possible to select the attributes themselves instead of the blocks first.
Never give up hope. Autodesk will fix it one day.

 

While they're at it, they could fix :N and :U :(

Link to comment
Share on other sites

Never give up hope. Autodesk will fix it one day. [ATTACH]28098[/ATTACH]
Yes, but I want to be alive when they do! :shock:

 

As for :N, I have seen it work ... sort of ... sometimes :lol: ... but not in this case!

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