Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to detect an entity located in a specified coordinate?

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Caladbolgll
403 Views, 6 Replies

How to detect an entity located in a specified coordinate?

Capture.JPG

Image attached above is part of the drawing that the macro I'm developing will be applied.

I have hundreds of block references (large rectangle with small grey rectangle on four corners) laid in nice gridlines (fixed distances between row & column), except there are few empty places. My task is to figure out number of small rectangles in the entire area.

To do so, I'm making an algorithm to build a 2D array that resembles whether if a block reference is found in each of the location.

For example:

(while (<= rowNum rowMax)
  (while (<= colNum colMax)
    (if (*block reference exists in (x,y)*)
      (*(colNum, rowNum) = T*)
) (setq colNum (1+ colNum)
(setq x (+ x colDist)
) (setq rowNum (1+ rowNum)
(setq y (+ y rowDist)
)

(This a very, very rough draft. Coding for the line between ** will have to be written as multiple lines in real program)

(assume x&y are x&y coordinates in the model space, and rowNum&colNum are row&column numbers of 2D array)

 

Rest of the part can be very easily created, but I do not know how to implement 3rd line in the example.

I'd love your help if you know any regarding this issue.

 

PS

Also, for some reason, the origin of the block reference is miles away from the centre (about 300x times of the object's size). Any advice on offsetting this other than modifying the block?

 

 

 

6 REPLIES 6
Message 2 of 7
Kent1Cooper
in reply to: Caladbolgll

If there's some element of the Blocks at the grid locations [regardless of where their insertion points are], rather than those locations being in empty space presumably inside the Blocks, and if there is not more than one Block having an element at such locations [overlapping], try:

 

(ssget (list x y) '((0 . "INSERT")))

 

to find such a Block.  You can also narrow it down further with such filters as the Block name, the Layer it's on, etc.

Kent Cooper, AIA
Message 3 of 7
hmsilva
in reply to: Caladbolgll

Hi Caladbolgll,
as the block dimensions are constant, and I don't have that block, I attched this image for better understanding of the hardcoded dimensions.

Caladbolgll_01.PNG

 

As a starting point, I would use something like this to to count small rectangles

 

(if (and (setq colMax (getreal "\nEnter the number of columns: "))
         (setq rowMax (getreal "\nEnter the number of rows: "))
         (setq pt (getpoint "\nPick base point: "))
    )
  (progn
    (setq colNum 0
          rowNum 0
          colDist 1.0
          rowDist 0.8
          num 0
          pt1 pt
    )
    (command "_.zoom" pt (list (+ (car pt) (* colMax colDist)) (+ (cadr pt) (* rowMax rowDist))))
    (while (<= rowNum rowMax)
      (while (<= colNum colMax)
        (if (setq ss (ssget "_C" pt1 pt1 '((0 . "INSERT") (2 . "a"))))
          (setq num (1+ num))
        )
        (setq colNum (1+ colNum)
              pt1    (list (+ (car pt1) colDist) (cadr pt1))
        )
      )
      (setq rowNum (1+ rowNum)
            pt1    (list (car pt) (+ (cadr pt1) rowDist))
            colNum 0
      )
    )
  )
)

 

To fix the block insertion point, I would suggest Lee Mac's Change Block Base Point (look at CBPR function)

 

Hope that helps
Henrique

EESignature

Message 4 of 7
hmsilva
in reply to: Caladbolgll

Caladbolgll,
Sorry I can't edit my previous post,
in the (2 . "a") in my previous post, the "a" is your block name...

Henrique

EESignature

Message 5 of 7
Caladbolgll
in reply to: Kent1Cooper

Are there any way to remove the fuzz distance?

Since the window is being zoomed up so far (due to the size of the area), ssget doesn't grab the proper block after certain size of the area.

Message 6 of 7
Kent1Cooper
in reply to: Caladbolgll


@Caladbolgll wrote:

Are there any way to remove the fuzz distance?

Since the window is being zoomed up so far (due to the size of the area), ssget doesn't grab the proper block after certain size of the area.


Maybe a crossing window with a defined size?  If an appropriate "box" is, say, 0.1 drawing units either way around the desired point, presumably being smaller than your Pickbox size at backed-off zoom levels, then perhaps something like this would work:

 

(ssget "_C"

  (list (+ x 0.1) (+ y 0.1))

  (list (- x 0.1) (- y 0.1))

  '((0 . "INSERT"))

)

 

If that doesn't do it, a routine could be made to first Zoom to a level appropriate for unambiguous selection around that desired location, usin ZOOM's Center option.

Kent Cooper, AIA
Message 7 of 7
stevor
in reply to: hmsilva

Sometimes it is expedient to collect all the likely objects

in the "C" or "W" window, and then select the one

closest to some point, like your 'coordinate.

 

One caveat for the point used for each object:

the Block Insert point may not serve your purposes,

so you may need to recalculate them, also.

S

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost