Selecting a specific block by name AND location

Selecting a specific block by name AND location

Anonymous
Not applicable
3,560 Views
6 Replies
Message 1 of 7

Selecting a specific block by name AND location

Anonymous
Not applicable

Hello,

 

I have a scenario where I have multiples of the same block within a drawing and I only want to move or delete a specific one.

 

I know the insert point location and the block name of the specific block I want to interact with.

 

 

I see on this forum how to select every block by name, but I am wondering if there is a way to only select a block by name at that specific x,y coordinate.

 

Block Example.PNG

In this example, I have 3 blocks named " blockA", I only want to move/delete the middle one.

Is this possible or is their another way to try and go about doing this?

 

Thank you for the help, this is my first post and I am new to AutoLISP so any reference to resources which could assist would also be appreciated.

0 Likes
Accepted solutions (1)
3,561 Views
6 Replies
Replies (6)
Message 2 of 7

Ranjit_Singh
Advisor
Advisor

@Anonymous wrote:

.........

In this example, I have 3 blocks named " blockA", I only want to move/delete the middle one.......


You can use dxf 10 code

(ssget "_x" '((0 . "insert") (10 xval yval zval)))

But not very reliable since the insertion point might be a floating point value with several decimals. but if you know the values to the last decimal then it should work. You can always use dxf -4 to allow some flexibility.BLOCK@IP.gif

 

0 Likes
Message 3 of 7

ВeekeeCZ
Consultant
Consultant

I took some routine on my disk (unfortunately author unknown to me) and little adjusted...

 

(vl-load-com)

(defun C:BlocksByNameAndPoint ( / e ss objs blk) ; by name
  (setq e (getstring T "\nType block name(s) to select (comma-delimited list or wildcards): ")
        pnt (getpoint "\nPoint coordinate: ")
        objs (ssadd)
        precision 1e-2 ; change
        )
  (if (setq ss (ssget "_X" '((0 . "INSERT"))))
    (progn
      (repeat (setq i (sslength ss))
        (setq name (strcase (vla-get-effectivename (vlax-ename->vla-object (setq blk (ssname ss (setq i (1- i)))))))
              point (cdr (assoc 10 (entget blk))))
        (if (and (wcmatch name (strcase e))
                 (equal (car pnt) (car point) precision)
                 (equal (cadr pnt) (cadr point) precision)
                 (equal (last pnt) (last point) precision)
                 )
          (ssadd blk objs)))
      (sssetfirst nil objs)))
  (princ)
)

You can set the precision.

0 Likes
Message 4 of 7

john.uhden
Mentor
Mentor

Not that I mind the extra code at all ('cause no one would ever notice the difference), but I think you can use just

(equal pnt point precision)

John F. Uhden

Message 5 of 7

Anonymous
Not applicable

Hey,

Thank for the LISP code. I am trying it out, but wonder if you can see what might be causing it not to work as expected for me.

 

I have loaded the lisp file. 

I run the command:

Block_Select_Command.png

 

I tried changing the:

"precision 1e-2 ; change"

to

"precision 1  ; change"

But, still no luck.

I don't get any errors, but the block is not being selected, the goal is to have it selected

(as if I had clicked on it) so I can then call a move command and relocate it.

 

Below is the block's properties that I am trying to select.

 

 

Block_Select_Properties.png

 

 

I relies, I can just type in the coordinates from the move or erase command, but I was hopeful that this would be usable if I had two different blocks at the same location.

 

TIA

0 Likes
Message 6 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

It works for me. Only I can think of is that you're using UCS.

Otherwise post a sample if you can, or save in somewhere on a cloud and send the link as a PM.

 

(vl-load-com)

(defun C:BlocksByNameAndPoint ( / e ss objs blk) ; by name
  (setq e (getstring T "\nType block name(s) to select (comma-delimited list or wildcards): ")
        pnt (getpoint "\nPoint coordinates: ")
        objs (ssadd)
        precision 1 ; change
        )
  (if (setq ss (ssget "_X" '((0 . "INSERT"))))
    (progn
      (repeat (setq i (sslength ss))
        (setq name (strcase (vla-get-effectivename (vlax-ename->vla-object (setq blk (ssname ss (setq i (1- i)))))))
	      point (trans (cdr (assoc 10 (entget blk))) 0 1))
        (if (and (wcmatch name (strcase e))
                 (equal pnt point precision)
                 )
          (ssadd blk objs)))
      (sssetfirst nil objs)))
  (princ)
)

 

Thanks @john.uhden for reminding me that.

0 Likes
Message 7 of 7

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

... I am wondering if there is a way to only select a block by name at that specific x,y coordinate....

>>and<<

....if I had two different blocks at the same location.


If you know the X and Y as numbers  [i.e. not by picking a location -- if you have to use (getpoint), you presumably know the location on-screen, and may as well just pick the Block(s)], and if they'll be nice clean values [I don't think a fuzz factor is possible], no code is needed -- you can use QSELECT to find them.  First run it with the Block name to find all of them, and then, from within the selection found by name, run it for the X and/or Y coordinate values of the position.  In your example image, you'd presumably need only the X-coordinate follow-up, unless there might be others vertically aligned with that location, above and/or below the area of the image.

Kent Cooper, AIA
0 Likes