Drawings SDK Developer Guide > Working with .dwg Files > Working with Entities > Working with Specific Entitites > Working with Lightweight Polylines > Editing Lightweight Polyline Vertices
Editing Lightweight Polyline Vertices

A lightweight polyline consists of connected segments having different widths, so that the end of the current segment is the start of the next segment. A point in which two segments are connected is a vertex. Vertices define the track along which straight and circular segments are drawn and influence the geometrical shape of a lightweight polyline. The polyline enumerates its own vertices beginning at zero (first is zero, second is one, third is two, etc.).

The lightweight polyline object provides methods for getting the number of vertices, getting the coordinates of vertices, adding a new vertex, deleting a vertex, relocating an existing vertex, and identifying a vertex. In the examples, the pLWPL variable stores a pointer to the lightweight polyline object.

Number of vertices

A lightweight polyline stores the number of vertices and segments, which are enumerated starting at zero. The start vertex has a zero index. The last vertex has the number that is the number of vertices minus one. A lightweight polyline does not contain vertices by default.

To get the number of vertices, use the numVerts() method returns number as an Integer value. For example:


OdInt16 count = pLWPL->numVerts();

OdConsoleString(L"\nVertices = %d", count);

Getting a vertex

A lightweight polyline stores two-dimensional coordinates of vertices in object coordinate systems, however it can return coordinates of vertices both in two-dimensional coordinates and in three-dimensional coordinates in world coordinate systems.

To get a vertex, use the getPointAt() method which requires the vertex index as the first argument of the Integer type and either a two-dimensional point as an instance of the OdGePoint2d type or a three-dimensional point as an instance of the OdGePoint3d type as the second argument in which the vertex coordinates must be saved, and returns the point through the second argument. For example:


OdGePoint2d point2d;
OdGePoint3d point3d;

OdInt16 index, count = pLWPL->numVerts();

for(index = 0 ; index < count ; index++)
{
  pLWPL->getPointAt(index, point2d);
  pLWPL->getPointAt(index, point3d);

  OdConsoleString(L"\nVertex (%d) places in OCS(%g,%g), in WCS(%g,%g,%g)", 
                  index, point2d.x, point2d.y, point3d.x, point3d.y, point3d.z);
}

Adding a vertex

A lightweight polyline can add a new vertex in any position using a vertex index. A new vertex automatically adds a new segment from the previous vertex to the new vertex. The number of vertices increases by one. The polyline object requires two-dimensional coordinates in OCS for adding a new vertex.

To add a vertex to the polyline, use the addVertexAt() method which requires the vertex index as the first argument of the Integer type and two-dimensional coordinates as the second argument of the OdGePoint2d type. For example:


pLWPL->addVertexAt( 0, OdGePoint2d(0.5, 0.5) );

pLWPL->addVertexAt( 1, OdGePoint2d(6.5, 1.2) );

pLWPL->addVertexAt( 2, OdGePoint2d(3.2, 4.8) );

OdConsoleString(L"\nVertices = %d", pLWPL->numVerts());

Note: The addVertexAt() method has three optional arguments that specifies parameters of the segment passed from the previous vertex to the new vertex and one optional argument that specifies an identifier for the new vertex. If an identifier is not specified, it obtains the index value.

Relocating a vertex

The two-dimensional location of a lightweight polyline's vertices can be changed using the indices. Relocation is performed in OCS. After relocating a vertex, the polyline changes its own track.

To relocate a vertex of a polyline, use the setPointAt() method which requires an index of the vertex to be moved as the first argument of an Integer type and new two-dimensional coordinates for the vertex as the second argument of the OdGePoint2d type. For example:


pLWPL->setPointAt( 0, OdGePoint2d(0.4, 0.6) );

pLWPL->setPointAt( 1, OdGePoint2d(7.2, 1.5) );

pLWPL->setPointAt( 2, OdGePoint2d(4.3, 5.6) );

Note: The setPointAt() method does not change the number of vertices and does not change identifiers of vertices. If the specified index is out of range, errors occur.

Identifying a vertex

A lightweight polyline allows associating an integer identifier with a vertex. Identifiers can be used for accessing a vertex.

To get an identifier of a vertex, use the getVertexIdentifierAt() method which requires an index of the vertex as an argument of the Integer type and returns its identifier as an Integer type. For example:


OdInt32 id, index, count = pLWPL->numVerts();

for(index = 0 ; index < count ; index++)
{
  id = pLWPL->getVertexIdentifierAt( index );
  OdConsoleString(L"\nVertex(%d)ID = %d", index, id);
}

To set an identifier for a vertex, use the getVertexIdentifierAt() method which requires an index of the vertex as the first argument of the Integer type and an identifier as the second argument of the Integer type. For example:


pLWPL->setVertexIdentifierAt(0, 0x80);
pLWPL->setVertexIdentifierAt(1, 0x08);

Deleting a vertex

A lightweight polyline allows deleting a vertex using its index. The number of vertices decreases by one.

To delete a vertex from a polyline, use the removeVertexAt() method which requires an index of the vertex to be deleted as an argument of the Integer type. For example:


pLWPL->removeVertexAt( 2 );

OdConsoleString(L"\nVertices = %d", pLWPL->numVerts());

Resetting the vertex data

The reset() method resets the vertex data of the lightweight polyline entity. This method requires the reuse status to retain the vertex data as the first argument of the Boolean type and the number of vertices to be retained as the second argument of the Integer type. If the reuse status is True, the set of vertices is expanded or is truncated so that it exactly retains the specified number of vertices. If the reuse status is False, all vertices are deleted. For example:


pLWPL->reset( true, 2 );

See Also

Working with Lightweight Polylines

Editing Lightweight Polyline Segments

Example of Working with the Lightweight Polyline Object

Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.