Remove a vertex

Remove a vertex

Anonymous
Not applicable
912 Views
2 Replies
Message 1 of 3

Remove a vertex

Anonymous
Not applicable
So as my topic says, how do I remove a vertex from a polyline3d?

Thank for replying,
Bert
0 Likes
913 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
[code]
static void DelVertex(void)
{
ads_name ssName;
ads_point ptres;
int nRet = acedEntSel(_T("\nSelect 3D-polyline: "), ssName, ptres);
if(nRet!=RTNORM) {
acutPrintf(_T("\nLine not selected"));
return;
}

AcDbObjectId lineId;
AcDbObjectIterator *pVtxIt = NULL;
AcDbObjectIdArray aVtxIds;
int iVtx = 1;
if (acdbGetObjectId(lineId, ssName) == Acad::eOk) {
AcDbObjectPointer pPoly(lineId, AcDb::kForWrite);
if (pPoly.openStatus() != Acad::eOk) return;
pVtxIt = pPoly->vertexIterator();
AcDbObjectId firstId = pVtxIt->objectId();
if(pVtxIt->objectId().isErased()) {
pVtxIt->step();
firstId = pVtxIt->objectId();
}
for (pVtxIt->setPosition(firstId); !pVtxIt->done(); pVtxIt->step()){
if(pVtxIt->objectId().isErased()) continue;
aVtxIds.append(pVtxIt->objectId());
}
delete pVtxIt;
} else return;
ACHAR prompt[128]=_T("");
sprintf(prompt,_T("\nSelect number of vertex (1 - %d): "),aVtxIds.length());
Acad:ErrorStatus es;
while (acedGetInt(prompt,&iVtx) == RTNORM && (iVtx < 1 || iVtx > aVtxIds.length())) {
acutPrintf(_T("\nError vertex number!"));
}
if (iVtx >= 1 && iVtx <= aVtxIds.length()) {
{
AcDbObjectPointer pVt(aVtxIds[iVtx-1], AcDb::kForWrite);
if (pVt.openStatus() == Acad::eOk) {
es = pVt->erase(true);
if (es != Acad::eOk) {
acutPrintf(_T("\nError deleting vertex: %s"), acadErrorStatusText(es));
}
}
}
{
AcDbObjectPointer pPoly(lineId, AcDb::kForWrite);
if (pPoly.openStatus() == Acad::eOk) {
pPoly->recordGraphicsModified(true);
}
}
}
}
[/code]
0 Likes
Message 3 of 3

Anonymous
Not applicable
Thanks for your reply. It's very nice. But I forgot to say that I'm not used to C# and C++ code. I tried to understand but it seems that I'm not there for now. Look at my code. It works but it do nothing.

PS.: Forget about the transaction, it's initialized and finished outside the function.

Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry

Module MyFunctions
Function CorrectCoordinates(ByVal Poly3d As Polyline3d) As Point3dCollection
Dim P3dCol As New Point3dCollection

Try
For Each objID As ObjectId In Poly3d

Dim vtx As PolylineVertex3d = BertTrans.GetObject(objID, OpenMode.ForRead)
If P3dCol.Count > 0 Then

If vtx.Position.IsEqualTo(P3dCol(P3dCol.Count - 1), New Tolerance(0, 0.001)) Then
vtx.UpgradeOpen()

'I try to erase the vertex from here!
vtx.Erase()
vtx.Dispose()

Else
P3dCol.Add(vtx.Position)
End If

Else
P3dCol.Add(vtx.Position)
End If

Next
Return P3dCol
Catch ex As Exception
MsgBox(ex.Message)
Return Nothing
End Try

End Function

End Module

Thank,
Bert
0 Likes