// Accepts the object ID of an AcDb2dPolyline, opens it, and gets // a vertex iterator. It then iterates through the vertices, // printing out the vertex location. // void iterate(AcDbObjectId plineId) { AcDb2dPolyline *pPline; acdbOpenObject(pPline, plineId, AcDb::kForRead); AcDbObjectIterator *pVertIter= pPline->vertexIterator(); pPline->close(); // Finished with the pline header. AcDb2dVertex *pVertex; AcGePoint3d location; AcDbObjectId vertexObjId; for (int vertexNumber = 0; !pVertIter->done(); vertexNumber++, pVertIter->step()) { vertexObjId = pVertIter->objectId(); acdbOpenObject(pVertex, vertexObjId, AcDb::kForRead); location = pVertex->position(); pVertex->close(); acutPrintf(_T("\nVertex #%d's location is") _T(" : %0.3f, %0.3f, %0.3f"), vertexNumber, location[X], location[Y], location[Z]); } delete pVertIter; }
void createPolyline() { // Set four vertex locations for the pline. // AcGePoint3dArray ptArr; ptArr.setLogicalLength(4); for (int i = 0; i < 4; i++) { ptArr[i].set((double)(i/2), (double)(i%2), 0.0); } // Dynamically allocate an AcDb2dPolyline object, // given four vertex elements whose locations are supplied // in ptArr. The polyline has no elevation, and is // explicitly set as closed. The polyline is simple; // that is, not curve fit or a spline. By default, the // widths are all 0.0 and there are no bulge factors. // AcDb2dPolyline *pNewPline = new AcDb2dPolyline( AcDb::k2dSimplePoly, ptArr, 0.0, Adesk::kTrue); pNewPline->setColorIndex(3); // Get a pointer to a Block Table object. // AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForRead); // Get a pointer to the MODEL_SPACE BlockTableRecord. // AcDbBlockTableRecord *pBlockTableRecord; pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); pBlockTable->close(); // Append the pline object to the database and // obtain its Object ID. // AcDbObjectId plineObjId; pBlockTableRecord->appendAcDbEntity(plineObjId, pNewPline); pBlockTableRecord->close(); // Make the pline object reside on layer "0". // pNewPline->setLayer("0"); pNewPline->close(); }
CCadEntity * CCadEntityFactory::GetCadEntity(AcDbEntity * entity) { CCadEntity * cadEntity = 0; if (entity->isKindOf(AcDbPoint::desc()) || entity->isKindOf(AcDbText::desc()) || entity->isKindOf(AcDbMText::desc()) || entity->isKindOf(AcDbBlockReference::desc())) { cadEntity = new CCadPoint(entity); } else if (entity->isKindOf(AcDbLine::desc()) || entity->isKindOf(AcDbArc::desc()) || entity->isKindOf(AcDbSpline::desc())) { cadEntity = new CCadLine(entity); } else if (entity->isKindOf(AcDbEllipse::desc()) || entity->isKindOf(AcDbCircle::desc())) { cadEntity = new CCadPolygon(entity); } else if (entity->isKindOf(AcDb2dPolyline::desc())) { AcDb2dPolyline * e = AcDb2dPolyline::cast(entity); if (e->isClosed()) cadEntity = new CCadPolygon(entity); else cadEntity = new CCadLine(entity); } else if (entity->isKindOf(AcDbPolyline::desc())) { AcDbPolyline * e = AcDbPolyline::cast(entity); if (e->isClosed()) cadEntity = new CCadPolygon(entity); else cadEntity = new CCadLine(entity); } resbuf * data = entity->xData(APPNAME); if (data != NULL) cadEntity->SetData(CFeatureData(data->rbnext->resval.rstring)); acutRelRb(data); return cadEntity; }