Lisp: select only blocks in selection, disregard rest

Lisp: select only blocks in selection, disregard rest

Anonymous
Not applicable
3,970 Views
12 Replies
Message 1 of 13

Lisp: select only blocks in selection, disregard rest

Anonymous
Not applicable

Hi and thanks in advance for taking time to read this.

 

I'm looking for a lisp so i can filter all non-blocks out of a selection.

Preferably after I've made a selection I'ld like to type this command and only have "blocks" in my selection, so I can 'group' them. 

 

 

I don't want to use "quick selection" cause I have to use too frequently (and I always have to select all the settings).

Anybody have any ideas?

 

 

Thanks

0 Likes
Accepted solutions (1)
3,971 Views
12 Replies
Replies (12)
Message 2 of 13

rkmcswain
Mentor
Mentor

Do you mean you want to make a selection on screen, and have it return only block insertions?

 

Perhaps something like this?

 

(setq sset (ssget '((0 . "INSERT"))))
R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 3 of 13

Anonymous
Not applicable

Correct, First I want to make a selection (blocks with other stuff like lines, circles, text etc).
Then I want to type the command, and have only remaining blocks, so I can group them.

 

The other way around would also work (first command then selection, then group)

 

 

If I load it like this however, I can't group it

(defun C:XCLUDE	(
			/
			)

(setq sset (ssget '((0 . "INSERT"))))
(princ)
)
0 Likes
Message 4 of 13

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

.... First I want to make a selection (blocks with other stuff like lines, circles, text etc).
Then I want to type the command, and have only remaining blocks, so I can group them.

...

 

Try this [in simplest terms, minimally tested]:

(defun C:SBO () ; = Selected Blocks Only
  (if (ssget "_I"); there are preselected objects [= Implied selection]
    (sssetfirst nil (ssget "_I" '((0 . "INSERT")))); select/grip/highlight only Blocks among them
  )
)

[That will also include "INSERT" object types other than just Block references, such as XREF, MINSERT, WMF.]

Kent Cooper, AIA
Message 5 of 13

Anonymous
Not applicable

Thank you so much, this works like a charm.

What line do I have to add so it will also "group" the remaining items?

 

(command "group")
or
(command "_.group")

doesn't seem to work

0 Likes
Message 6 of 13

patrick.ouellet-fortin
Contributor
Contributor

Is there any way to use it and select specifically a block named "TEST" by exemple?

0 Likes
Message 7 of 13

Kent1Cooper
Consultant
Consultant

@patrick.ouellet-fortin wrote:

Is there any way to use it and select specifically a block named "TEST" by exemple?


As long as it's not a dynamic Block [which can't be filtered for by Block name].  Just add the entry for Block name:

 

(sssetfirst nil (ssget "_I" '((0 . "INSERT") (2 . "TEST"))))

 

Kent Cooper, AIA
0 Likes
Message 8 of 13

patrick.ouellet-fortin
Contributor
Contributor

Thank you!

0 Likes
Message 9 of 13

diagodose2009
Collaborator
Collaborator

You can old method inside Block/s.  If you develope visual-lisp, then you can send the variable  

 

 (setq a208 (ssget))
  (setq disregard (ssget "X" (cons 0 "INSERT")))
 

 

 You call the function (setq selectonlyblocks (dfn_ssg_xor a208 disregard))

You use this function , when you do not need selectall method.

 

0 Likes
Message 10 of 13

cmacdonald
Contributor
Contributor

@Kent1Cooper Question.  Also to preface, I have absolutely no experience with LISP.  Just trying to follow along here.  So apologies in advance if I sound silly!

Do wildcards work where that block name field is?  In other words would (2 . "*CAEX*") work in place of that?

I have block definitions uniquely identified and appended with _CAEX to allow doing QSE and entering attribute information in to instances of said blocks, and then later be extracted into tables.  But, as the OP said each time I need to update attribute information in can be a total time suck redoing all of the settings in Quick Select prompt.

 

Also, is there really no way to do the same thing with a dynamic block?  Again, I am simply filtering these blocks out for attribute editing purposes.  But they do have visibility states, stretch commands, etc.

 

TIA

-Chris

0 Likes
Message 11 of 13

Sea-Haven
Mentor
Mentor

Q1 (2 . "*CAEX*")  should work

Copy this line to command line

(princ (sslength (ssget "X" (list (cons 0  "INSERT")(cons 2  "*CAEX*")))))

 

Q2 dynamic blocks yes can get dynamic properties, visibility state name, Distance 1 and so on. Use Lee-mac dynamic block properties lsp.

 

Depending on how complex it all becomes worst case is you may need to pay for some help, but in mean time explain more, need a sample dwg to match your requests.

Message 12 of 13

Kent1Cooper
Consultant
Consultant

@cmacdonald wrote:

....
Do wildcards work where that block name field is?  In other words would (2 . "*CAEX*") work in place of that?
....

Also, is there really no way to do the same thing with a dynamic block?  ....


Yes to the first, no to the second if by "the same thing" you mean by way of (ssget).  It can read only things in the entity data list, and the underlying Block name of a dynamic Block insertion isn't in there.  You would need to find all Blocks [filtered by whatever criteria work for you, such as only those on a particular Layer], and step through the selection, checking the effective name of each, removing those that don't have the right one from the selection.  You can find many examples of how to get the effective name in this Forum or the base AutoCAD Forum.

Kent Cooper, AIA
Message 13 of 13

cmacdonald
Contributor
Contributor

Thanks gents!

0 Likes