.NET

## .NET

Valued Contributor
Posts: 64
Registered: ‎02-03-2012
Message 1 of 7 (274 Views)

# Detect if selected point of polyline is its a vertex - how?

274 Views, 6 Replies
02-10-2012 01:02 PM

Hello!

I would like to know if there is any way to detect if selected point of the selected polyline is its vertex?

1. The user is drawing rectangle or any other figure with polyline.

2. Entering command "GetMe".

3. Selecting polyline.

4. Selecting point.

Is there any built-in function in Autodesk's API?

Thanks.

Valued Contributor
Posts: 95
Registered: ‎11-15-2011
Message 2 of 7 (264 Views)

# Re: Detect if selected point of polyline is its a vertex - how?

02-10-2012 02:17 PM in reply to: GrzesiekGP

hi, i think there is not.

therefore i think you have to either collect the points from user to start off with or explode the poly and collect start and endpts, and then compare each to the pickedpoint from the entity selection result.

felix

Valued Mentor
Posts: 312
Registered: ‎04-11-2010
Message 3 of 7 (254 Views)

# Re: Detect if selected point of polyline is its a vertex - how?

02-10-2012 08:24 PM in reply to: FFlix

Hi,

You don't need to explode the polyline, just iterate the parameters, get the point at each parameter value and add it to a Point3dCollection and then check if the picked point is in the collection. By other side i believe it's *very* dificult for a user to pick exactly in a vertex without osnap, and so I think you need a tolerance to check the the distance from the picked point to the vertex for each one.

something like this:

Dim pcol As New Point3dCollection
Dim fp, lp As Double

fp = pline.StartParam
lp = pline.EndParam

For i = fp To lp
Next

'Aproach 1

If pcol.Contains(PickedPoint) then

...

Else

...

End If

'Aproach 2

For each p as Point3D in pcol

If p.DistanceTo(Pickedpoint) <= Tolerance then

...

Exit For

Else

....

End If

Next

Gaston Nunez

Valued Contributor
Posts: 95
Registered: ‎11-15-2011
Message 4 of 7 (243 Views)

# Re: Detect if selected point of polyline is its a vertex - how?

02-11-2012 07:49 AM in reply to: gasty1001

hi gaston

exploding simply allows you to separate the polyline into its individual sections, lines or arcs, bulge or not etc, which gives you the sought of vertices.

with no tolerance there's an infinite amount of parameter values in a curve; with tolerance you still don't know whether or not any parameter value happens to be one of the polyline's vertices. i agree, with regards to point3d-accuracy and tolerance, it matters whether or not grip selection is enabled for selection, however, i don't think this applies to the prompt entity selection.

apart from start and endpoint, the polyline's vertices, e.g. number and location, once it is a dbobject are not known. the polyline has a .getlineat(integer) method which looks appropriate enough to get to the vertices, however, the integer iteration maximum is, i believe, not known. and also, it only works if the section is in fact a line section as opposed to an arc section. exploding simply allows bypassing the information surrounding the vertices, and the original polyline is retained (unless it is explicitly erased separately).

felix

Valued Mentor
Posts: 312
Registered: ‎04-11-2010
Message 5 of 7 (233 Views)

# Re: Detect if selected point of polyline is its a vertex - how?

02-11-2012 09:39 AM in reply to: FFlix

Hi Felix,

I deeply disagree, you can obtain the NumberOfVertices property of the Polyline object and then get the point at each vertex with GetPoint3dAt using the vertex index, in the same way as with GetPointAtParameter (the vertex are positioned at increments of 1 from the start parameter to the end parameter, no matter if there are arcs in between). The curve class and its derivates has a lot of methods to obtain data from its geometry, properties and structure without the need to explode the objects. Jus check it, no more than 10 lines of code (other than doc,db,transaction, etc).

Gaston Nunez

Valued Contributor
Posts: 95
Registered: ‎11-15-2011
Message 6 of 7 (224 Views)

# Re: Detect if selected point of polyline is its a vertex - how?

02-11-2012 11:30 AM in reply to: gasty1001

well, you are right, i've overlooked the polyline.numberofvertices property, and yes, i agree that traversing the polyline to collect the points is probably more elegant than exploding it, provided that that fits in with the overall task.

going back to the original question however, the polyline hasn't got a method of comparing a pickedpoint to its vertices, i.e. the points still need to be collected and traversed for comparison whichever way its done. so, holding onto the user's initial input points may still be advantagous (together with a tolerance for the pickedpoint property).

Moderator
Posts: 1,269
Registered: ‎04-09-2008
Message 7 of 7 (206 Views)

# Re: Detect if selected point of polyline is its a vertex - how?

02-12-2012 07:37 AM in reply to: GrzesiekGP

For polyline is true that rule: if  GetParameterAtPoint method return value equal integer - then that integer is a index of polyline vertex (zero based).

Пожалуйста не забывайте про Утвердить в качестве решения и Баллы
Please remember to Accept as Solution and Kudos

Recently Solved