By Fenton Webb
Issue
Is there any way to remove a vertex from AcDb2dPolyline/AcDb3dPolyline (similar to AcDbPolyline::removeVertexAt() ) ?
Solution
There is no analogous removal function for 2d and 3d polylines, mainly because the storage mechanisms are different. AcDbPolyline more efficiently stores its vertices as an array within a single entity, whereas for 2d and 3d polylines, vertices are stored as separate entities. Therefore, you will have to access an individual vertex entity and explicitly delete it; deletion doesn't occur through the 2d/3d polyline entity itself. Try following code snippet.
Look at the following code snippet: which will remove the first vertex.
void EraseVertex()
{
ads_name name; ads_point pt;
// pick a polyline 2d
int res = acedEntSel(_T("\nPick a 2dpolyline"), name, pt);
// if ok
if (res == RTNORM)
{
AcDbObjectId plineObjId;
// convert the ename to an AcDbObjectId
Acad::ErrorStatus es = acdbGetObjectId(plineObjId, name);
AcDbObjectPointer<AcDb2dPolyline> pPlineEnt(plineObjId, AcDb::kForRead);
// if we have the right entity type
if (pPlineEnt.openStatus() == Acad::eOk)
{
AcDbObjectIterator* pVertIter = pPlineEnt->vertexIterator();
// select the 1st vertex in AcDb2dPolyline; regen to see change
AcDbObjectPointer<AcDb2dVertex> pVertex(pVertIter->objectId(), AcDb::kForWrite);
// check to see if it is not already erased
if (es != Acad::eWasErased)
{
Adesk::Boolean bErased = pVertex->isErased();
if (!bErased)
es = pVertex->erase();
}
}
delete pVertIter;
}
}