此示例演示如何创建对象并设置其某些属性 — 图层、颜色索引、封闭参数。然后,它会创建四个顶点对象 (),设置它们的位置,并将它们追加到折线对象。最后,它关闭所有打开的对象 - 顶点、折线、块表记录和块表。关闭折线对象后,AutoCAD 会自动向其添加该对象。AcDb2dPolylineAcDb2dPolylineVertexAcDbSequenceEnd 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();
}
|
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-29 17:10
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.