ham 发表于 2006-7-5 17:12:00

再次请教!

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

pglyxq 发表于 2006-7-5 23:51:00

ham 发表于 2006-7-6 01:08:00

<P>谢谢二楼大虾,不过我按照你说的改了其中的:</P>
<P>if((es=pDb-&gt;insert(blockId, pBlockName,pNewDb, true))==Acad::eOk) <BR>&nbsp;&nbsp;{ <BR>&nbsp;&nbsp;&nbsp;acutPrintf("\ninsert ok\n"); <BR>&nbsp;&nbsp;&nbsp;delete pNewDb; <BR>&nbsp;&nbsp;} <BR>&nbsp;&nbsp;else <BR>&nbsp;&nbsp;{ <BR>&nbsp;&nbsp;&nbsp;AfxMessageBox("Insert failed"); <BR>&nbsp;&nbsp;&nbsp;delete pNewDb; <BR>&nbsp;&nbsp;&nbsp;return; <BR>&nbsp;&nbsp;} </P>
<P>删除了pNewDb数据库,但是问题依旧啊。。。。。。</P>
<P>是不是因为加了这句:acDocManager-&gt;lockDocument(curDoc(),AcAp::kWrite,NULL,NULL,true);锁定了文档,使图块写不尽去了呢,但是不加这句 程序就出错误,而且将解锁语句acDocManager-&gt;unlockDocument(curDoc());&nbsp;提前也会出错,头疼。。。。</P>

ham 发表于 2006-7-6 01:12:00

一边看世界杯,一边想问题,呵呵,ppstream这个网络电视不错,播放很流畅。

ham 发表于 2006-7-6 23:33:00

<P>还是想不出来,那位大虾帮帮忙啊,不用输入数据的图块能显示,但是有的图块要求输入一些信息的显示不出来,如果用autocad的insert命令通过对话框也可以加入,和锁定文档没什么关系,那位大虾帮忙想想办法!!!</P>
<P>&nbsp;</P>

ham 发表于 2006-7-7 22:52:00

<P>???/</P>
<P>请教高手,帮忙看看,。。。。。。。。。急。。。</P>

ham 发表于 2006-7-8 08:18:00

<P>这个问题应该等价于如何用arx来实现autocad中的insert命令,不过不是动态的,是静态的,也就是并不要求用户输入数据,各位认为如何去做,请教。。。。</P>

ham 发表于 2006-7-8 17:09:00

<P>咋没人理我呢???????</P>

ham 发表于 2006-7-10 22:09:00

<P>搞定了,!!!!</P>
<P>代码没变,我也不知道怎么就可以了,,,,</P>
页: [1]
查看完整版本: 再次请教!