Polyline.GetClosestPointTo giving wrong result

Polyline.GetClosestPointTo giving wrong result

Anonymous
Not applicable
1,650 Views
4 Replies
Message 1 of 5

Polyline.GetClosestPointTo giving wrong result

Anonymous
Not applicable

Hi All,

 

I am using AutoCAD 2012 & VS 2010.

 

I have polyline feature with coordinates 1. X=11992.9202, Y=2035.9537. 2. X= 12452, Y=2039.8486. 3. X=13280, Y=2046.8707

 

i have written code to select the polyline and also written to select nea point.

 

selected nearest point is 'X=12838.076824 and Y = 2043.121578'

 

1.When i try to use get param point, getting exception 'eInvalidInput'. expecting closest point.

2. Wheni try to use get closest point then i am getting resltent point foraway i.e X=507534.76892 and Y=6159118.6698.

 

So i am not getting the proper result. i dont know where the issues. stuck with issue long time.

 

Any support much appriciated.

 

Regards,

Dayalan

0 Likes
Accepted solutions (1)
1,651 Views
4 Replies
Replies (4)
Message 2 of 5

Alfred.NESWADBA
Consultant
Consultant
Accepted solution

Hi,

 

the values you show seems strange, so 2 ideas for now:

a) are you sure that you don't have a UCS (other than WCS) active?

b) if yes please upload this drawing + the code-snippet of a sample, that we see the exact code you are using and this can be reproduced by others

 

>> When i try to use get param point, getting exception 'eInvalidInput'. expecting closest point.

I guess you mean the function GetParameterAtPoint? ... there you need to ask for a point that is exactly on that curve. By default I use first the GetClosestPointTo and the resulting point I forward to the GetParameterAtPoint function.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 5

Anonymous
Not applicable

Hi,

 

Thanks for your mail.

 

here i attached drawing file and code as zip.

 

Can you please review and suggest.

 

 

Thank you.

 

Dayalan

0 Likes
Message 4 of 5

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

first I get an exception as the polyline you used get's accessed outside the active transaction. That is not safe.

I then converted part of the code to create a transaction before I use the polyline.GetClosestPointTo and then polyline.GetParameterAtPoint and can't see any differences between the values I get reported from VisualStudio and the ones from AutoCAD directly.

 

So either the issue is that you close/dispose your transaction before you try to get properties from it (or calculations like polyline.Get...) or I'm doing anything in another way than you do. I see that I have to start command "11", but what points I should show or what entity I have to select then ... don't know that.

 

The code I created to get the point1 and point2 converted to parameter is that (in VB.NET, you can convert it using public converters in the www).

 

      Dim tTrAct As Transaction = Nothing
      Try
         tTrAct = centerLineEntity.Database.TransactionManager.StartOpenCloseTransaction
         Dim tCurve As Curve = TryCast(tTrAct.GetObject(centerLineEntity.ObjectId, OpenMode.ForRead), Curve)
         If tCurve IsNot Nothing Then
            'get param for first point
            Dim pintNea As Point3d = tCurve.GetClosestPointTo(startPoint, False)
            Dim paramStart As Double = tCurve.GetParameterAtPoint(pintNea)
            'get param for second point
            Dim pintNea2 As Point3d = tCurve.GetClosestPointTo(endPoint, False)
            Dim paramEnd As Double = tCurve.GetParameterAtPoint(pintNea2)
         End If
      Catch generatedExceptionName As System.Exception
         'TODO exception handling
      Finally
         If tTrAct IsNot Nothing Then tTrAct.Dispose() : tTrAct = Nothing
      End Try

 

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 5 of 5

Anonymous
Not applicable

Hi

 

I understand and resolved the issue. My drawing is having some custom UCS. I set to World and now my custom code is working fine as expected.

 

 

Thanks for your support

 

Regards,

Dayalan

0 Likes