// 在内存上创建一个新的对象
AcGePoint3d ptStart(0, 0, 0);
AcGePoint3d ptEnd(100, 100, 0);
AcDbLine *pLine = new AcDbLine(ptStart, ptEnd);
//再加一条
AcGePoint3d ptStart1(0, 0, 0);
AcGePoint3d ptEnd1(0, 100, 0);
AcDbLine *pLine1 = new AcDbLine(ptStart1, ptEnd1);
// 获得指向块表的指针
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlockTable, AcDb::kForRead);
// 获得指向特定的块表记录(模型空间)的指针
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
AcDb::kForWrite);
// 将AcDbLine类的对象添加到块表记录中
AcDbObjectId lineId;
pBlockTableRecord->appendAcDbEntity(lineId, pLine);
// 将第二条线也加进模型空间中
pBlockTableRecord->appendAcDbEntity(lineId, pLine1);
//虽然这么写不太严谨,但后面你对lineId也没做什么操作所以就这么给你添加上了,希望你能了解就好
// 关闭图形数据库的各种对象
pBlockTable->close();
pBlockTableRecord->close();
pLine->close();
//千万别忘了关闭实体,否则日后头疼的问题会出现很多
pLine1->close(); |