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

Possible to pull out coordinates from an object when an object snap is applied?

4 REPLIES 4
Reply
Message 1 of 5
mdhutchinson
407 Views, 4 Replies

Possible to pull out coordinates from an object when an object snap is applied?

I have a rather simple 3rd party custom object... I tried to get its bounding box but the coordinates that come back don't seem to relate at all to the object.

What I'd like are the coordinates of two nodes the object contains...

Is it possible to apply the autocad cursor in some why with the node object snap to get their coordinates?

 

4 REPLIES 4
Message 2 of 5
Lee_Mac
in reply to: mdhutchinson

If you can't access the object's constituent parts, maybe use the osnap function, e.g.

 

(if (setq pt (getpoint "\nPick Point: "))
    (setq pt (osnap pt "_nod"))
)

 

Message 3 of 5
Kent1Cooper
in reply to: mdhutchinson


@mdhutchinson wrote:

I have a rather simple 3rd party custom object... I tried to get its bounding box but the coordinates that come back don't seem to relate at all to the object.

What I'd like are the coordinates of two nodes the object contains...

Is it possible to apply the autocad cursor in some why with the node object snap to get their coordinates?


Is this thing a Block?  If so, you should be able to get at its parts, and it wouldn't be hard to step through them until you find two Point entities.  You'd need to convert their positional information, which will be in relation to the Block's insertion point, rather than in drawing coordinates.

 

If it's not, does it at least have something like an insertion point?  Whether it does or not, you'd need the user to pick it, or pick in it, and that would give you a starting location.  I could imagine a way to apply Node object snap there, and in a pattern working around in increments a little smaller than the Aperture System Variable, to blanket the area [perhaps like the sunflower-seed pattern made by Vogel's Formula in a recent thread].  When it first finds a point, save that.  Whenever it finds one from another spot, compare whether it's the same one it found before, and if so, ignore it and continue looking.  Once it finds one it didn't find before, save that and stop looking, and you have your two points.

 

That depends, of course, on there not being other Point entities or Dimension definition points in the vicinity, that it could find instead of the ones you want it to.

Kent Cooper, AIA
Message 4 of 5
Kent1Cooper
in reply to: Kent1Cooper


Kent1Cooper wrote:

.... you'd need ... a starting location.  I could imagine a way to apply Node object snap there, and in a pattern working around in increments a little smaller than the Aperture System Variable, to blanket the area [perhaps like the sunflower-seed pattern made by Vogel's Formula in a recent thread].  When it first finds a point, save that.  Whenever it finds one from another spot, compare whether it's the same one it found before, and if so, ignore it and continue looking.  Once it finds one it didn't find before, save that and stop looking, and you have your two points.

....


Sort of like this [minimally tested, without various controls you might want]:

 

(defun C:F2P (/ n start chkstep pt done); = Find 2 Points
  (setq
    n 0
    start (getpoint "\nSpecify place to start looking: ")
    chkstep
      ; increment of about 1/4 of Aperture System Variable, to
      ; ensure Osnap aperture boxes overlap to blanket area
      (/
        (getvar 'viewsize); in drawing units
        (/ (cadr (getvar 'screensize)) (getvar 'aperture))
          ; both in pixels - number of aperture heights in screen height
        4 ; [could well work at smaller value...]
      );  / & chkstep
  ); setq
  (while (and (not done) (< n 500)); limit number of tries
    (if
      (setq pt ; find a Point?
        (osnap
          (polar ; Vogel's Formula
            start; point
            (/; angle
              (* 2 pi (setq n (1+ n)))
              (1+ (/ (1+ (sqrt 5)) 2))
            ); end /
            (* (sqrt n) chkstep); distance adjusted for zoom level
          ); end polar
          "_nod"
        ); end osnap
      ); end setq
      (if (not pt1); then [found a Point] - no pt1 yet?
        (setq pt1 pt); then - put it in pt1
        (if (not (equal pt1 pt)); else - already a pt1 - is this different?
          (setq pt2 pt done T); then - put it in pt2 and stop looking
        ); if
      ); if
    ); if
  ); while
); defun

 

The first two Points if finds will then be in the pt1 and pt2 variables.

 

Whether 500 tries is enough would depend on how much of the screen the object fills -- if there are two Points but it doesn't find them both, increase the 500, or Zoom out further.

 

You could replace the designation of a starting location with a selection of the object if it has something like an insertion point that you could extract to use as a starting location.  You could add notifications if it didn't find any Points, or found only one, or whatever.

 

EDIT:  If the custom object is 3-dimensional, and used at different orientations, I can imagine that the two Points in it could sometimes be vertically one above the other, or even just too close to each other from the current view direction's point of view, in which case this routine might always "see" the same one, and wouldn't find both.  Compensation for that might be possible with enough information about the object [change coordinate system to look from another direction, or something].

Kent Cooper, AIA
Message 5 of 5
stevor
in reply to: mdhutchinson

Suppose that you cannot or will not use LeeMac's 'node method, you might use a grread routine to test for an node osnap find when the cursor hovers long enough; or, make a search pattern covering a suspected area based on the Aperture size, also by node osnap.
S

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

Post to forums  

Autodesk Design & Make Report

”Boost