ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to remove a vertex from AcDb2dPolyline?

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
402 Views, 4 Replies

How to remove a vertex from AcDb2dPolyline?

Hi, all!

How can I remove a vertex from AcDb2dPolyline? I couldn't find any
"removeVertex" or similar function in AcDb2dPolyline class so I simply
iterated through the vertices, opened their objects and called the erase()
function. Everything looked all right at first, my polyline has changed in
the way I wanted, but in AutoCAD's Properties dialog none of the vertex data
were displayed, and AutoCAD crashed soon after with "Out of memory" alert.

What is the correct way to do this?


Robert
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

Your decision seems correctly. Please, publish your code for error checking.
Message 3 of 5
Anonymous
in reply to: Anonymous

In fact, after debugging my code I found out that only when I remove the
first vertex, AutoCAD Properties dialog box doesn't display any vertex data!
In all other cases, everything is working well. In both cases, AutoCAD keeps
running and everything seems ok.

If the first vertex is deleted and then the drawing is saved and reopened,
everything works fine.

This is my code:

int testMain ()
{
ads_name e;
ads_point pt;
int i = 0, iVert;
if (acedEntSel ("\n Select 2dPoly...", e, pt) != RTNORM) return 0;

if (acedGetInt ("\n Which vertex to remove (0 - first, 1 - second...)? ",
&iVert) != RTNORM) return 0;

AcDbObjectId idPoly, idVert;
if (acdbGetObjectId (idPoly, e) != Acad::eOk) return 0;

AcDb2dPolyline *pPoly = NULL;
AcDb2dVertex *pVert = NULL;

if (acdbOpenObject ((AcDbObject*&)pPoly, idPoly, AcDb::kForWrite) ==
Acad::eOk)
{
if (pPoly->isA() == AcDb2dPolyline::desc())
{
AcDbObjectIterator *vIter = pPoly->vertexIterator ();
vIter->start ();
while (!vIter->done ())
{
if (i == iVert)
{
idVert = vIter->objectId ();
if (pPoly->openVertex(pVert, idVert, AcDb::kForWrite) == Acad::eOk)
{
pVert->erase();
pVert->close();
}
}
i++;
vIter->step();
}
}
pPoly->close();
}
return 1;
}





"dgoceva" wrote in message
news:f1099e8.0@WebX.maYIadrTaRb...
Your decision seems correctly. Please, publish your code for error checking.
Message 4 of 5
Anonymous
in reply to: Anonymous

Perhaps the vertex iterator is corrupt when you remove one. Try break after
finding and deleting the correct one.

"Robert Tencic" wrote in message
news:EEAB67BF859EDCDE9B6ED716A51FF58D@in.WebX.maYIadrTaRb...
> In fact, after debugging my code I found out that only when I remove the
> first vertex, AutoCAD Properties dialog box doesn't display any vertex
data!
> In all other cases, everything is working well. In both cases, AutoCAD
keeps
> running and everything seems ok.
>
> If the first vertex is deleted and then the drawing is saved and reopened,
> everything works fine.
>
> This is my code:
>
> int testMain ()
> {
> ads_name e;
> ads_point pt;
> int i = 0, iVert;
> if (acedEntSel ("\n Select 2dPoly...", e, pt) != RTNORM) return 0;
>
> if (acedGetInt ("\n Which vertex to remove (0 - first, 1 - second...)? ",
> &iVert) != RTNORM) return 0;
>
> AcDbObjectId idPoly, idVert;
> if (acdbGetObjectId (idPoly, e) != Acad::eOk) return 0;
>
> AcDb2dPolyline *pPoly = NULL;
> AcDb2dVertex *pVert = NULL;
>
> if (acdbOpenObject ((AcDbObject*&)pPoly, idPoly, AcDb::kForWrite) ==
> Acad::eOk)
> {
> if (pPoly->isA() == AcDb2dPolyline::desc())
> {
> AcDbObjectIterator *vIter = pPoly->vertexIterator ();
> vIter->start ();
> while (!vIter->done ())
> {
> if (i == iVert)
> {
> idVert = vIter->objectId ();
> if (pPoly->openVertex(pVert, idVert, AcDb::kForWrite) == Acad::eOk)
> {
> pVert->erase();
> pVert->close();
> }
> }
> i++;
> vIter->step();
> }
> }
> pPoly->close();
> }
> return 1;
> }
>
>
>
>
>
> "dgoceva" wrote in message
> news:f1099e8.0@WebX.maYIadrTaRb...
> Your decision seems correctly. Please, publish your code for error
checking.
>
>
Message 5 of 5
Anonymous
in reply to: Anonymous

Well,

I received an answer from ADN regarding my problem and they confirmed it to
be a problem with AutoCAD's Properties dialog. This is due because the
erase() function doesn't realy delete an object from the database, it just
marks it for deleting like it says in the manual. And that's why everything
looks ok when the drawing is saved and reopened.

Thanks for your help, guys!


"David Bartliff" wrote in message
news:B0556DCB4B37E44527F0716E292B3D48@in.WebX.maYIadrTaRb...
> Perhaps the vertex iterator is corrupt when you remove one. Try break
after
> finding and deleting the correct one.
>
> "Robert Tencic" wrote in message
> news:EEAB67BF859EDCDE9B6ED716A51FF58D@in.WebX.maYIadrTaRb...
> > In fact, after debugging my code I found out that only when I remove the
> > first vertex, AutoCAD Properties dialog box doesn't display any vertex
> data!
> > In all other cases, everything is working well. In both cases, AutoCAD
> keeps
> > running and everything seems ok.
> >
> > If the first vertex is deleted and then the drawing is saved and
reopened,
> > everything works fine.
> >
> > This is my code:
> >
> > int testMain ()
> > {
> > ads_name e;
> > ads_point pt;
> > int i = 0, iVert;
> > if (acedEntSel ("\n Select 2dPoly...", e, pt) != RTNORM) return 0;
> >
> > if (acedGetInt ("\n Which vertex to remove (0 - first, 1 - second...)?
",
> > &iVert) != RTNORM) return 0;
> >
> > AcDbObjectId idPoly, idVert;
> > if (acdbGetObjectId (idPoly, e) != Acad::eOk) return 0;
> >
> > AcDb2dPolyline *pPoly = NULL;
> > AcDb2dVertex *pVert = NULL;
> >
> > if (acdbOpenObject ((AcDbObject*&)pPoly, idPoly, AcDb::kForWrite) ==
> > Acad::eOk)
> > {
> > if (pPoly->isA() == AcDb2dPolyline::desc())
> > {
> > AcDbObjectIterator *vIter = pPoly->vertexIterator ();
> > vIter->start ();
> > while (!vIter->done ())
> > {
> > if (i == iVert)
> > {
> > idVert = vIter->objectId ();
> > if (pPoly->openVertex(pVert, idVert, AcDb::kForWrite) == Acad::eOk)
> > {
> > pVert->erase();
> > pVert->close();
> > }
> > }
> > i++;
> > vIter->step();
> > }
> > }
> > pPoly->close();
> > }
> > return 1;
> > }
> >
> >
> >
> >
> >
> > "dgoceva" wrote in message
> > news:f1099e8.0@WebX.maYIadrTaRb...
> > Your decision seems correctly. Please, publish your code for error
> checking.
> >
> >
>
>

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost