Jump to content
Developer Wiki and Function Reference Links ×

GetClosestPt it just dont work


Recommended Posts

Hello all, I am trying to use GetClosestPt to work on even simple squares or lines but all the VARs returned are zero.

VAR obj:HANDLE;

ptX, ptY :REAL;

index :INTEGER;

containedObj :LONGINT;

BEGIN

GetPt(ptX, ptY);

GetClosestPt(obj, ptX, ptY, index, containedObj);

SetPenFore(obj, 65535, 0, 0);

END;

I have a reasonable amount of experience programming vs but I just cant get this to work. Is there something obvious left out of the function reference guide.

Link to comment

Hi Matie,

Two things, you are missing a few lines from the example that is posted in the VS Function Reference. The full script is (with one line added):

PROCEDURE GetClosestPtExample;

VAR

???obj :HANDLE;

???ptX, ptY :REAL;

???index :INTEGER;

???containedObj :LONGINT;

BEGIN

???GetPt(ptX, ptY);

???obj := PickObject(ptX, ptY); { you need this line }

???GetClosestPt(obj, ptX, ptY, index, containedObj);

???SetPenFore(obj, 65535, 0, 0);

???{ the following line shows the values of your variables at the end of the script }

???message('obj= ', obj, ' X= ', ptx, ' Y= ', pty, ' ', index, ' ', containedObj);

END;

RUN(GetClosestPtExample);

Second, when you run the script and click in the drawing you have to be close enough to an object for it to be selected; the same as you would if you were trying to select it manually. Clicking in an open region will return zero in your "obj" variable.

HTH,

Raymond

Edited by MullinRJ
Link to comment

Hi Raymond,

I'm not sure that this is the way the function was intended to be used. The whole point of GetClosestPt ,as described in the function ref guide, is that it returns the handle of the closest object to the user point. In your example you seem to be forwarding the handle (obj) to GetClosestPt when in fact it should be returning a handle????? Now I'm totally confused!

Link to comment

Mattie,

???I don't think it ever worked the way you want. It would be nice if it did. Perhaps if you temporarily open up your snap radius to as large as it will go before clicking then resetting it after you get your object, it might act more like you desire.

???Use pref numbers 1009 and 1010 with GetPref() and SetPref(). If you need help with this, write back.

Raymond

Link to comment

Raymond,

I'm only going by the Bible (funct ref). GetClosestPt returns a handle to 'obj'. The problem is ..what object. Is it only for subobjects as the description seems to suggest.

The code you suggested defeats the purpose of 'closest point' because you are effectively selecting the object manually by using PickObject. I personally think there is definately some code or syntax missing from the funct ref. The lack of proper manuals on this language is getting me down!!!

Matt

Link to comment

I refrain from trusting bibles and rely more heavily on observation. I'm from the school of trial and error. Bibles are full of good intentions, but historically are not factual.

Without knowing what you are trying to do, I cannot offer sound advice on which path to take. There's usually more than one way to approach each problem, so if this command doesn't suit your needs, others might.

The whole point of GetClosestPt ,as described in the function ref guide, is that it returns the handle of the closest object to the user point. In your example you seem to be forwarding the handle (obj) to GetClosestPt when in fact it should be returning a handle?????

You are right, the bible does say that, but the code acts differently. If you want it to work as advertised, you should file a bug.

In the meantime, describe what you are trying to do and maybe someone out here can suggest a decent solution or workaround.

Raymond

PS - In your search for truth, keep good notes.

Link to comment
  • 1 month later...
Guest Mark Flamer

I am also using this command in a script. I have spent hours trying to find a way to get a handle to the "sub Object" within a PIO that you are returned an index to from this command. Does any one know if this is possible? The only use I have found for this index is for setting a parametric constraint. It worked fine for me in that case, is that all it's for? Thanks.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...