Hi,
Could anyone let me know how to get the entities / segments that made up the polyline.
(Need to access the entity which is already created. type is AcDb2dPolyline)
here is my code till now.
//ask user to select an entity ads_name ss; int rc = acedSSGet( NULL, NULL, NULL, NULL, ss ); if (rc != RTNORM) { acutPrintf(L"Nothing selected.\n", rc); return; } long length; acedSSLength( ss, &length ); if (RTNORM != length || 0 == length) { acedSSFree( ss ); return; } ads_name en; for (int i = 0 ; i < length; i++) { acedSSName(ss, i, en); AcDbObject* ptrOBJ; AcDbEntity *pEnt = NULL; AcDbObjectId objectId; acdbGetObjectId(objectId, en); acdbOpenObject(ptrOBJ, objectId, AcDb::kForRead); const ACHAR *ClassName = ptrOBJ-> isA()->name(); AcDbPolyline *pPolyline; AcDb2dPolyline *p2DPolyline; int numVerts = 0; int numArcs = 0; int numLines = 0; if ( NULL != ( pPolyline = AcDbPolyline::cast( ptrOBJ ))) { numVerts = pPolyline->numVerts(); numSegs = numVerts - 1; int segType = 0; for(int i = 0; i <= numSegs; i++) { switch(pPolyline->segType(i)) { case AcDbPolyline::kLine: numLines++; break; case AcDbPolyline::kArc: numArcs++; break; default: break; } } acutPrintf(L"No of Lines in pPolyline %d\n", numLines ); acutPrintf(L"No of Arcs in pPolyline %d\n", numArcs ); } else if ( NULL != ( p2DPolyline = AcDb2dPolyline::cast( ptrOBJ ))) { numVerts = 0; AcDbObjectIterator *pIter; pIter = p2DPolyline->vertexIterator(); for (pIter->start(); !pIter->done(); pIter->step()) { numVerts++; } if (numVerts != 4) { delete pIter; return ; } else { // need to find the segments here as in the case of AcDbPolyline } } }
thanks in advance...
Regards,
Maddy
Use
AcDbObjectIterator::objectId()
to get the object id of the vertex, then use acdbOpenObject() to open it kForRead.
Hi, Owen
i think by doing so we can open only the vertex for reading purpose not the lines and curves which make up the polyline...
if this is the case then how to access the polyline entities?
anyway i'll try to work it out as per your suggestion......
Thanks for your kind reply...
Regards,
Maddy
Polyline segments are defined by the vertices; they are not separate objects.
for AcDbPolyline you just collect a quantity of linear/arc segments
If it's your goal :), use bulge() for each vertex if AcDb2dPolyline. if the result is 0.0 - linear segment, if != 0.0 - arc
AcDbObjectIterator *pIter = pPoly2D->vertexIterator(); if (pIter) { int iVert = 0; for (; !pIter->done(); pIter->step()) { if (!pIter->objectId().isErased()) { AcDbObjectId objId = pIter->objectId(); AcDbObjectPointer<AcDb2dVertex> pVert(objId,AcDb::kForRead); if (pVert.openStatus() == Acad::eOk) { // pVert->bulge() can be used here } } } }
PS: if you don't want problems with memory leak
1. you MUST free ClassName. use acutDelString(ClassName);
2. for{...} acedSSFree( ss );
3. delete pIter; imho useless and may help autocad to die :). you did not created it, leave it alone 🙂