AcDbObjectId CDraw::CreateBlock(AcDbDatabase *pDb,CString blkName,AcGePoint3d origin,int num,...) { // 获得当前图形数据库的块表 AcDbBlockTable *pBlkTbl; /*acdbHostApplicationServices()->workingDatabase() ->getBlockTable(pBlkTbl, AcDb::kForWrite);*/ pDb->getSymbolTable(pBlkTbl, AcDb::kForRead); // 创建新的块表记录 AcDbBlockTableRecord *pBlkTblRcd; pBlkTblRcd = new AcDbBlockTableRecord(); /* AcDbBlockTableRecord *pBlkTblRcd; pBlkTbl->getAt(ACDB_MODEL_SPACE,pBlkTblRcd,AcDb::kForWrite);*/ // 根据用户的输入设置块表记录的名称 //char blkName[40]; //if (acedGetString(Adesk::kFalse, "\n输入图块的名称:", blkName) != // RTNORM) //{ // pBlkTbl->close(); // delete pBlkTblRcd; // return; //} pBlkTblRcd->setName(blkName); // 将块表记录添加到块表中 AcDbObjectId blkDefId; pBlkTblRcd->setOrigin(origin); pBlkTbl->add(blkDefId, pBlkTblRcd); //为什么运行到这出错,提示eNotOpenWrite?高手帮帮忙? pBlkTbl->close(); // 向块表记录中添加实体 AcDbObjectId entId; va_list pa; va_start( pa, num ); /* Initialize variable arguments. */ for(int i=0;i<num;i++) { AcDbEntity *pEnt; pEnt = va_arg( pa, AcDbEntity*); pBlkTblRcd->appendAcDbEntity(entId, pEnt); pEnt->close(); } va_end( pa ); // 关闭实体和块表记录 pBlkTblRcd->close(); return blkDefId; } |