再次请教各位大虾:程序代码如下,完全是参考的例子上的:
dwgpath="D:\\Drawing1.dwg"; acDocManager->lockDocument(curDoc(),AcAp::kWrite,NULL,NULL,true); AcDbDatabase *pNewDb =new AcDbDatabase(Adesk::kFalse);
Acad::ErrorStatus es=pNewDb->readDwgFile(dwgpath , _SH_DENYNO); if (es!=Acad::eOk) { acutPrintf("\nThe file %s cannot be opend",dwgpath); return; } AcDbDatabase *pDb; pDb =acdbHostApplicationServices ()->workingDatabase (); CString pBlockName=BlockDwg; AcDbObjectId blockId; //出问题的地方 if((es=pDb->insert(blockId, pBlockName,pNewDb, true))==Acad::eOk) { acutPrintf("\ninsert ok\n"); } else { AfxMessageBox("Insert failed"); delete pNewDb; return; } const AcGePoint3d& Pt=AcGePoint3d(0,0,0); double Angle=0; double XrefScale=0; AcDbBlockReference *pBlkRef = new AcDbBlockReference; pBlkRef->setBlockTableRecord(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(); AcDbBlockTableRecord *pBlockDef; acdbOpenObject(pBlockDef, blockId, AcDb::kForRead); AcDbBlockTableRecordIterator *pIterator; pBlockDef->newIterator(pIterator); AcGePoint3d basePoint; AcDbEntity *pEnt; AcDbAttributeDefinition *pAttdef; for (pIterator->start(); !pIterator->done(); pIterator->step())//将source.dwg中所有的Attibute进行遍历 { pIterator->getEntity(pEnt, AcDb::kForRead); pAttdef = AcDbAttributeDefinition::cast(pEnt); if (pAttdef != NULL && !pAttdef->isConstant()) { AcDbAttribute *pAtt = new AcDbAttribute(); pAtt->setPropertiesFrom(pAttdef); pAtt->setInvisible(pAttdef->isInvisible()); basePoint = pAttdef->position(); basePoint += pBlkRef->position().asVector(); pAtt->setPosition(basePoint); pAtt->setHeight(pAttdef->height()); pAtt->setRotation(pAttdef->rotation()); pAtt->setTag("Tag"); pAtt->setFieldLength(25); char *pStr = pAttdef->tag(); pAtt->setTag(pStr); acutDelString(pStr); pAtt->setFieldLength(pAttdef->fieldLength()); pAtt->setTextString("-"); AcDbObjectId attId; pBlkRef->appendAttribute(attId, pAtt); pAtt->close(); } pEnt->close(); // use pEnt... pAttdef might be NULL } delete pIterator;
acDocManager->unlockDocument(curDoc());
程序编译无误,也将dwg文件的块插到当前稳当的数据库中了,但是不知为什么,视图上并没有显示,查找当前的数据库,发现块名在里面,就是没有图形,请教各位!
另外在AcDbObjectId blockId;这句话时,调试时出现了find symbols对话框,要求查找acdbhdr.pdb文件,cancel掉以后程序能继续执行,真是奇怪,是vc的毛病么,请教!
我的程序是在非模对话框的单击事件里调用的,不知是不是有影响,谢谢各位! |