Selection set from block name in lisp?

Selection set from block name in lisp?

Anonymous
Not applicable
550 Views
9 Replies
Message 1 of 10

Selection set from block name in lisp?

Anonymous
Not applicable
How can I create a selection set from a block name, then assign that set to a variable?

For example, let's say I have a block called "door1." I want to assign door1 as a selection set to variable "x" so that I can do the following...

(command "move" x "" "0,0" "@1,1")

I've tried tblsearch with no luck yet. I've noticed that I can pass the handle of the block, but I don't know how to get the handle from the name. User input (mouse click) is not an option.

Thanks,
Karen
0 Likes
551 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable
This will return a selection set of all blocks with the given name on the
current layout tab:
(defun getblocks (block)
(ssget "X" (list (cons 2 block) (cons 410 (getvar "CTAB"))))
)

You can use it like this:
(command "move" (getblocks "Test") "" "0,0" "@1,1")

Hope it helps

--
Get free software and more at http://www2.stonemedia.com/franko

"Karen" wrote in message
news:eee20f7.-1@WebX.SaUCah8kaAW...
> How can I create a selection set from a block name, then assign that set
to a variable?
>
> For example, let's say I have a block called "door1." I want to assign
door1 as a selection set to variable "x" so that I can do the following...
>
> (command "move" x "" "0,0" "@1,1")
>
> I've tried tblsearch with no luck yet. I've noticed that I can pass the
handle of the block, but I don't know how to get the handle from the name.
User input (mouse click) is not an option.
>
> Thanks,
> Karen
>
>
0 Likes
Message 3 of 10

Anonymous
Not applicable
(setq x (ssget "X" '((0 . "INSERT")(2 . "DOOR1"))))
0 Likes
Message 4 of 10

Anonymous
Not applicable
Good catch on the INSERT. I forgot about that one. But a word of caution:
SSGET will select all blocks matching the filter regardless of what layout
contains them. If this isn't desirable, you can add a group code 410 to
specify which layout to select the blocks from:

(defun getblocks (block)
(ssget "X" (list '(0 . "INSERT") (cons 2 block) (cons 410 (getvar
"CTAB"))))
)

--
Get free software and more at http://www2.stonemedia.com/franko

"Randy Richardson" wrote in message
news:eee20f7.1@WebX.SaUCah8kaAW...
> (setq x (ssget "X" '((0 . "INSERT")(2 . "DOOR1"))))
>
0 Likes
Message 5 of 10

Anonymous
Not applicable
Karen, if you are using AutoCAD 2000, Frank's advice is most likely good. I
can't verify it, because I'm using R14. Don't try the (cons 410... part if
you're using R14, because it will crash. By the way, when you post a
question, it is a good practice to specify what version you're using.
0 Likes
Message 6 of 10

Anonymous
Not applicable
Yet another good catch. You da man! 😃

--
Get free software and more at http://www2.stonemedia.com/franko

"Randy Richardson" wrote in message
news:eee20f7.3@WebX.SaUCah8kaAW...
> Karen, if you are using AutoCAD 2000, Frank's advice is most likely good.
I
> can't verify it, because I'm using R14. Don't try the (cons 410... part
if
> you're using R14, because it will crash. By the way, when you post a
> question, it is a good practice to specify what version you're using.
>
0 Likes
Message 7 of 10

Anonymous
Not applicable
Thanks you all, I've almost got it...

...but how do I pass the block name to the ssget? I can't seem to get it to work. (btw - A2K)

Given (setq b1 "door")
the following won't work...
(setq s1 (ssget "X" '((0 . "INSERT")(cons 2 b1))))
nor does
(setq dp1 (cons 2 b1))
(setq s1 (ssget "X" '((0 . "INSERT") dp1)))

What am I missing?

Thanks,
Karen
0 Likes
Message 8 of 10

Anonymous
Not applicable
The "AND" is implied by default.
(setq s1 (ssget "x" '((0 . "INSERT")(2 . "door")))) or
(setq s1 (ssget "x" (list '(0 . "INSERT")(cons 2 "door"))))
works just fine.
__
"Jimmy B" wrote in message
news:eee20f7.13@WebX.SaUCah8kaAW...
> Hello Karen,
>
> (setq s1 (ssget "X" (list '(-4 . " '(-4 . "AND>"))))
> or
> (setq s1 (ssget "X" '((-4 . " "AND>"))))
>
> Observere:
> (list must be used because of (cons 2 b1)
> ' must be added before the other ones exept (cons 2 b1)
> If all members of a list are constant values, you can use the '( ) to
explicitly define the list.
>
> --
> Best regards: Jimmy B
> CAD coordinator at Emtunga International AB
> www.emtunga.com
> Karen skrev i
diskussionsgruppsmeddelandet:eee20f7.6@WebX.SaUCah8kaAW...
> > Thanks you all, I've almost got it...
> >
> > ...but how do I pass the block name to the ssget? I can't seem to
get it to work. (btw - A2K)
> >
> > Given (setq b1 "door")
> > the following won't work...
> > (setq s1 (ssget "X" '((0 . "INSERT")(cons 2 b1))))
> > nor does
> > (setq dp1 (cons 2 b1))
> > (setq s1 (ssget "X" '((0 . "INSERT") dp1)))
> >
> > What am I missing?
> >
> > Thanks,
> > Karen
>
0 Likes
Message 9 of 10

Anonymous
Not applicable
You can use (ssget) to do this, like so:

(setq name "DOOR1") ;; Block name

(ssget "x" (list '(0 . "INSERT") (cons 2 name)))

Note that there is no need to filter a selection set
by layout (as Frank's example needlessly does) when
using the selection set in an interactive AutoCAD
command that operates on multiple objects (like MOVE
does). This is mainly because those type of commands
automatically restrict the selection to objects in the
current space. So, regardless of whether you submit a
selection set containing objects in spaces other than
the current space, they will be ignored.

Karen wrote:
>
> How can I create a selection set from a block name, then assign that set to a variable?
>
> For example, let's say I have a block called "door1." I want to assign door1 as a selection set to variable "x" so that I can do the following...
>
> (command "move" x "" "0,0" "@1,1")
>
> I've tried tblsearch with no luck yet. I've noticed that I can pass the handle of the block, but I don't know how to get the handle from the name. User input (mouse click) is not an option.
>
> Thanks,
> Karen

--
/*********************************************************/
/* Tony Tanzillo Design Automation Consulting */
/* Programming & Customization for AutoCAD & Compatibles */
/* ----------------------------------------------------- */
/* tony.tanzillo@worldnet.att.net */
/* http://ourworld.compuserve.com/homepages/tonyt */
/*********************************************************/
0 Likes
Message 10 of 10

Anonymous
Not applicable
You cannot pass a LISP symbol or expression in a quoted
list, as you're doing:

(ssget "x" '((0 . "INSERT") (cons 2 b1)))

The ' (quote) character supresses evaluation, so any
symbols in the list that is quoted will not evaluate
to their assigned values.

To use symbols in this way, you must avoid the
use of (quote), and use (list) instead:

(ssget "x" (list '(0 . "INSERT") (cons 2 b1)))

Karen wrote:
>
> Thanks you all, I've almost got it...
>
> ...but how do I pass the block name to the ssget? I can't seem to get it to work. (btw - A2K)
>
> Given (setq b1 "door")
> the following won't work...
> (setq s1 (ssget "X" '((0 . "INSERT")(cons 2 b1))))
> nor does
> (setq dp1 (cons 2 b1))
> (setq s1 (ssget "X" '((0 . "INSERT") dp1)))
>
> What am I missing?
>
> Thanks,
> Karen

--
/*********************************************************/
/* Tony Tanzillo Design Automation Consulting */
/* Programming & Customization for AutoCAD & Compatibles */
/* ----------------------------------------------------- */
/* tony.tanzillo@worldnet.att.net */
/* http://ourworld.compuserve.com/homepages/tonyt */
/*********************************************************/
0 Likes