Drawings SDK Developer Guide > Working with .dwg Files > Working with Entities > Working with Specific Entitites > Working with Multi-Lines > Editing Multi-Line Vertices
Editing Multi-Line Vertices

A set of parallel lines that forms a multi-line is a segment. A multi-line consists of connected segments, 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 parallel straight segments are drawn and influence the geometrical shape of a multi-line. Each line of a segment is drawn along an axis from the current vertex to the next vertex. This axis defines the direction vector for all lines. A line passed through a vertex from the kink of the first parallel line to the kink of the last parallel line in a vertex is a miter. The number of miters equals the number of vertices. The number of segments either equals the number of vertices for a closed multi-line or the number of vertices minus one for an open multi-line. A multi-line enumerates its own vertices, segments, and miters beginning at zero (first is zero, second is one, third is two, etc.).

The multi-line object provides methods for getting the number of vertices, getting the coordinates of vertices, getting the coordinates of an axis vector for segments, getting the coordinates of a direction vector for miters, adding a new vertex at the end of the multi-line, deleting the last vertex from the multi-line, relocating an existing vertex, and finding a line using specified coordinates. In the following examples, the pMLine variable stores a pointer to the multi-line object.

Number of vertices

A multi-line object stores the number of vertices, segments, and miters which are enumerated at zero. The start vertex has the number 0. The last vertex has the number that is the number of vertices minus one. A new vertex automatically gets the next index. A multi-line does not contain vertices by default.

To get the number of vertices, use the numVertices() method which does not have arguments and returns an Integer value. For example:


OdInt16 count = pMLine->numVertices();

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

Getting a vertex

To get a vertex, use the vertexAt() method which requires the vertex index as an argument of the Integer type and returns the three-dimensional point as an instance of the OdGePoint3d type. For example:


OdGePoint3d point;

OdInt16 index, count = pMLine->numVertices();

for(index = 0 ; index < count ; index++)
{
  point = pMLine->vertexAt( index );

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

Getting a miter

To get a miter direction, use the miterAt() method which requires the miter index as an argument of the Integer type and returns the three-dimensional unit vector as an instance of the OdGeVector3d type. For example:


OdGeVector3d miter;

OdInt16 index, count = pMLine->numVertices();

for(index = 0 ; index < count ; index++)
{
  miter = pMLine->miterAt( index );

  OdConsoleString(L"\nMiter (%d) directs to (%g,%g,%g)", index, miter.x, miter.y, miter.z);
}

Getting a segment axis

To get a segment axis, use the axisAt() method which requires the segment index as an argument of the Integer type and returns the three-dimensional unit vector as an instance of the OdGeVector3d type. The unit vector defines the axis along which all lines of the current segment are drawn. All lines of the multi-line are directed parallel to this axis. If the multi-line is open, the last segment is not taken into account. For example:


OdGeVector3d vector;

OdInt16 index = 0;
OdInt16 count = pMLine->numVertices() - ((pMLine->closedMline()) ? 0 : 1)

while(index < count)
{
  vector = pMLine->axisAt( index );

  OdConsoleString(L"\nSegment (%d) directs to (%g,%g,%g)", index, vector.x, vector.y, vector.z);
  index++;
}

Adding a vertex

The multi-line object adds a vertex always at the end, that is, the new vertex becomes the last vertex. A new vertex automatically adds a new segment from the last vertex to the new vertex. The number of vertices increases by one.

To add a vertex to the multi-line, use the appendSeg() method which requires the three-dimensional point as an argument of the OdGePoint3d type and does not return a value. For example:


pMLine->appendSeg( OdGePoint3d(1.5, 0.5, 0) );

pMLine->appendSeg( OdGePoint3d(4.2, 4.2, 0) );

pMLine->appendSeg( OdGePoint3d(6.5, 1.5, 0) );

OdConsoleString(L"\nVertices = %d", pMLine->numVertices());

Note: If the coordinates of a new vertex are located out of the multi-line plane, the appendSeg() method makes the projection of this vertex onto the multi-line plane and saves the projected coordinates of the new vertex.

Relocating a vertex

A multi-line object automatically recalculates the segment axis direction and miter direction when its vertex changes coordinates. After relocating a vertex, the multi-line changes its own track.

To relocate a vertex of a multi-line, use the moveVertexAt() method which requires an index of the vertex to be moved as the first argument of an Integer type and new coordinates for vertex as the second argument of the OdGePoint3d type. For example:


pMLine->moveVertexAt(0, OdGePoint3d(0.5, 2.5, 0));

pMLine->moveVertexAt(1, OdGePoint3d(3.8, 0.5, 0));

pMLine->moveVertexAt(2, OdGePoint3d(5.8, 4.6, 0));

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

Deleting a vertex

When deleting a vertex of a multi-line object, the last vertex is always the vertex to be deleted. The number of vertices decreases by one.

To delete a vertex from a multi-line, use the removeLastSeg() method which requires a reference to a variable of the OdGePoint3d type in which the coordinates of the deleted vertex must be saved as an argument and returns the three-dimensional point instance through this argument. For example:


OdGePoint3d point;

pMLine->removeLastSeg( point );

OdConsoleString(L"\nLast vertex (%g,%g,%g) is deleted", point.x, point.y, point.z);

Searching for a line

A multi-line may contain multiple parallel lines defined in its multi-line style. The multi-line object provides the ability to determine whether a line is on a point.

To catch a line in the multi-line, use the element() method which requires the three-dimensional point as an argument of the OdGePoint3d type and returns the order number of the line on which the specified point is placed as an Integer value or (–1) if the point is not placed on the line. The method returns the line index in order of the multi-line style definition. The value (–1) indicates that a line is not found. For example:


OdInt16 number = pMLine->element( OdGePoint3d(1.1, 1.8, 0) );

if(index != -1)
  OdConsoleString(L"\nPoint belongs to the line %d", number);
else
  OdConsoleString(L"\nLine is not found");

Note: The element() method returns the line index only if the specified point lies on the line.

See Also

Working with Multi-Lines

Specific Multi-Line Properties

Example of Working with the Multi-Line Object

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