我使用的是AutoCAD2004,按照论坛和书上的指导做了这个将图形作为图块插入的程序,可是怎么都不能在图纸上显示插入结果,手动插入的时候可以看见图形已经成为块,并可以顺利插入图块,但程序的插入代码并不起作用,为什么?请大家看一下。
CString sFileName = "D:\\cadMgr\\ptu.dwg"; CString pBlockName = "basePT"; AcGePoint3d Pt(200,200,0); double Angle = 0.0; AcGeScale3d XrefScale(1.,1.,1.); AcDbDatabase *pNewDb =new AcDbDatabase(Adesk::kFalse); int es=pNewDb->readDwgFile(sFileName,_SH_DENYNO,false); if (es!=Acad::eOk) { acutPrintf("\nThe file %s cannot be opend",sFileName); return; } AcDbDatabase *pDb; pDb =acdbHostApplicationServices ()->workingDatabase () ; AcDbObjectId blockId; if((es=pDb->insert(blockId, pBlockName,pNewDb, true))==Acad::eOk) { acutPrintf("\ninsert ok\n"); } else { AfxMessageBox("Insert failed"); delete pNewDb; return; } //程序到这里,后面仿佛就开始出错,我找不到原因。难道因为我用的盗版?? AcDbBlockReference *pBlkRef = new AcDbBlockReference; pBlkRef->setBlockTableRecord(blockId);//指向blockId; pBlkRef->setPosition(Pt);//设定位置 pBlkRef->setRotation(Angle);//设定转角 pBlkRef->setScaleFactors( XrefScale);//设定放大比例
AcDbBlockTable *pBlockTable; pDb->getSymbolTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord; pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); pBlockTable->close(); AcDbObjectId newEntId; pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef); pBlockTableRecord->close(); } |