插入块的问题,致命错误
//设置好文件名称 插入点 插入角度 后调用此函数完成<BR>void InsertTo_Demo(CString dwgFileName,AcGePoint3d ptInsert ,float fAngle)<BR>{<BR> <BR> AcDbObjectId id;<BR> AcDbDatabase *pDatabase;<BR> AcDbDatabase *pdb;<BR> pDatabase=new AcDbDatabase(FALSE); <BR> HRESULT hr = S_OK; <BR> hr=pDatabase->readDwgFile(baseFunc->CStringToPChar(dwgFileName)); <BR> if (hr!=S_OK)<BR> {<BR> CString strError;<BR> strError.Format("读取%s文件时出错!可能版本不匹配!",dwgFileName);<BR> AfxMessageBox(strError);<BR> return;<BR> }<BR> pdb=acdbHostApplicationServices()->workingDatabase();<BR> pdb->insert(id,<BR> baseFunc->CStringToPChar(dwgFileName),pDatabase);<BR> //delete pDatabase;<BR> pDatabase=NULL;<BR> AcDbBlockTable *pTable=NULL;<BR> acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pTable,<BR> AcDb::kForRead);<BR> <BR> ASSERT(pTable!=NULL);<BR> AcDbBlockTableRecord *pModelSpace;<BR> pTable->getAt(ACDB_MODEL_SPACE,pModelSpace,AcDb::kForWrite);<BR> pTable->close();<BR> AcDbBlockReference *pBlockRef; <BR> pBlockRef=new AcDbBlockReference(ptInsert,id);<BR> <BR> pBlockRef->setRotation(fAngle);<BR> AcGeScale3d scale; <BR> scale.sx=1;<BR> scale.sy=1;<BR> scale.sz=1;<BR> pBlockRef->setScaleFactors (scale); <BR> pModelSpace->appendAcDbEntity(pBlockRef);<BR> pModelSpace->close();<BR> pBlockRef->close();<BR>}<BR>编译没有问题,运行时,只要到了要关闭当前的图纸时,就有问题,致命错误。能保存能另存为。不能打开别的图纸,不能关闭当前图纸。
如果手动将插入的块删掉再关闭,还是有问题。
请高手帮忙 用Release编译试试,不要用Debug
或者输入SDI0
不知道对不对 AcDbDatabase *pDb=new AcDbDatabase();<br/> pDb->readDwgFile("d:\\test.dwg");<br/> AcDbObjectId id;<br/> acdbCurDwg()->insert(id,"测试",pDb);<br/> delete pDb;<br/> AcGePoint3d pos(0,0,0);<br/> AcDbBlockReference *pRef=new AcDbBlockReference(pos,id);<br/> AcDbBlockTable *pBlk=NULL;<br/> AcDbBlockTableRecord *pBlkR=NULL;<br/> acdbCurDwg()->getBlockTable(pBlk,OpenMode::kForRead);<br/> pBlk->getAt(ACDB_MODEL_SPACE,pBlkR,OpenMode::kForWrite);<br/> pBlk->close();<br/> if (Acad::ErrorStatus::eOk!=pBlkR->appendAcDbEntity(pRef))<br/> {<br/> delete pRef;<br/> }<br/> else<br/> {<br/> pRef->close();<br/> }<br/> pBlkR->close();<br/>给你串能正常执行的代码,自己瞧瞧看自己存在哪方面的问题。至于你的代码我实在没得时间看了。自己写省事儿……。<br/> <p>如果在多文档环境下,使用pDb->readDwgFile("d:\\test.dwg");函数需要锁定文档,可以使用如下代码来实现临时锁定文档,</p><p>class AFX_CLASS_EXPORT CTempDocLockOverride<br/>{<br/>public:<br/> CTempDocLockOverride();<br/> virtual ~CTempDocLockOverride();</p><p>private:<br/> AcApDocument* m_pDoc;<br/>};</p><p>CTempDocLockOverride::CTempDocLockOverride()<br/>{<br/> m_pDoc = acDocManager->curDocument();<br/> if(m_pDoc)<br/> acDocManager->lockDocument(m_pDoc);<br/>}</p><p>CTempDocLockOverride::~CTempDocLockOverride()<br/>{<br/> acDocManager->unlockDocument(m_pDoc);<br/>}<br/></p><p>//暂时锁定当前文档<br/>#define TEMPDOCLOCK() CTempDocLockOverride tempDocLock;</p><p></p><p>使用 TEMPDOCLOCK();宏即可实现临时锁定文档的功能。</p><p></p>
页:
[1]