Drawings SDK Developer Guide > Working with .dwg Files > Working with Entities > Working with Specific Entitites > Working with Leaders > Working with Leader Lines
Working with Leader Lines

In the following examples, the pLeader variable stores a pointer to the leader object.

Line fit type

A leader line can be a polyline or a spline curve.

To check whether the leader line is a spline or polyline type, use the isSplined() method, which returns "true" if the leader line is a curve. For example:


odPrintConsoleString(L"\nLeader line is %s", ((pLeader->isSplined()) ? L"curve" : L"polyline"));

To switch the leader line type, use the setToSplineLeader() and setToStraightLeader() methods, which require no parameters and allows users to change the line fit type. For example:


// Set "spline" line fit type
pLeader->setToSplineLeader();

// Set "polyline" line fit type
pLeader->setToStraightLeader() ;

Number of vertices

To get the number of vertices, use the numVertices() method, which requires no parameters and returns the number of vertices as an integer value. For example:


odPrintConsoleString(L"\nNumber of vertices is %d", pLeader->numVertices());

First and last vertex

The first vertex of the leader line is the arrowhead position. The last vertex is the nearest point to the leader annotation.

To get the first vertex, use the firstVertex() method which requires no parameters and returns the first vertex as an object of OdGePoint3d type. For example:


OdGePoint3d start;
start = pLeader->firstVertex();
odPrintConsoleString(L"\nStart vertex = (%g,%g,%g)", start.x, start.y, start.z);

To get the last vertex, use the lastVertex() method which requires no parameters and returns the first vertex as an object of OdGePoint3d type. For example:


OdGePoint3d end;
end = pLeader->lastVertex();
odPrintConsoleString(L"\nLast vertex = (%g,%g,%g)", end.x, end.y, end.z);

Getting and setting vertices

To get a vertex at a specified index, use the vertexAt() method, which requires one integer parameter to specify the vertex index and returns the vertex as an object of OdGePoint3d type. For example:


OdGePoint3d vertex;
for (int i=0; i < pLeader->numVertices(); i++)
{
  vertex = pLeader->vertexAt(i);
  odPrintConsoleString(L"\n vertex (%d) = (%g,%g,%g)", i, vertex.x, vertex.y, vertex.z);
}

To add a new vertex to the end of the leader vertex array, use the appendVertex() method, which requires one parameter of the OdGePoint3d class to specify the point to be set. For example:


OdGePoint3d point = OdGePoint3d(10,10,0);
pLeader->appendVertex(point);

Note: Every point is projected to the leader plane, so the plane should be specified before adding vertices.

To change the data of a vertex at the specified index of the leader vertex array, use the setVertexAt() method, which requires an integer parameter to specify the vertex index and an object of the OdGePoint3d class to specify the point data to be set. For example:


OdGePoint3d point = pLeader->vertexAt(1);
point.x += 5;
point.y += 5;
bool bSet = pLeader->setVertexAt(1, point);
if (bSet)
  odPrintConsoleString(L"\nVertex was successfully reset.");
else
  odPrintConsoleString(L"\nVertex was not reset.");

Note: The index should have a value from the vertex range, otherwise an exception occurs. Also this method does not reset vertices if one of the leader segments has zero length.

Deleting vertices

You can only remove the last vertex. To do so, use the removeLastVertex() method which requires no parameters and removes one vertex from the end of the vertex array. For example:


pLeader->removeLastVertex();

Line color

To get the color of the line and arrowhead, use the dimclrd() method which requires no parameters and returns the color as an object of the OdCmColor class. For example:


OdCmColor color = pLeader->dimclrd();
odPrintConsoleString(L"\nColor (%d %d %d)", color.red(), color.green(), color.blue());

To set a new value for the color, use the setDimclrd() method, which requires one reference to an object of the OdCmColor class to specify the new value for the color. For example:


OdCmColor color;
color.setRGB(255, 0, 0);
pLeader->setDimclrd(color);

See Also

Working with Leaders

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