zqljg 发表于 2005-2-20 14:02:00

[ARX]大家帮忙看一下这段程序

<BR>void InsertBlock(ads_point basePoint,double angle)<BR>{<BR>        AcDbDatabase *pDwg =new AcDbDatabase (Adesk::kFalse) ; <BR>        Acad::ErrorStatus es;<BR>        es=pDwg-&gt;readDwgFile ("C:\\ccd.dwg") ; <BR>        <BR>        if(es==Acad::eOk)<BR>        {<BR>                AfxMessageBox("readDwgFile Successful!");<BR>                return;<BR>        }<BR>        AcDbObjectId blockId ; <BR>        <BR>        es = acdbHostApplicationServices()-&gt;workingDatabase()-&gt;insert (blockId, "myfile", pDwg, <BR>                Adesk::kFalse) ; <BR>        if ( es != Acad::eOk ) <BR>                acutPrintf ("\n插入块错误.") ; <BR>        delete pDwg ; <BR>        <BR>        <BR>        AcDbBlockReference *pBlkRef =new AcDbBlockReference ; <BR>        pBlkRef-&gt;setBlockTableRecord (blockId) ;


        AcGePoint3d inbase(basePoint, basePoint, 0.0);        <BR>        pBlkRef-&gt;setPosition (inbase) ; <BR>        pBlkRef-&gt;setRotation (0.0) ;<BR>        pBlkRef-&gt;setScaleFactors(AcGeScale3d(1,1,1));<BR>        <BR>        AcDbBlockTable *pBlockTable ; <BR>        <BR>        es=acdbHostApplicationServices()-&gt;workingDatabase()-&gt;getBlockTable (pBlockTable, AcDb::kForRead) ; <BR>        if(es!=Acad::eOk)<BR>                acutPrintf("getBlockTable faile!");<BR>        <BR>        AcDbBlockTableRecord *pBlockTableRecord ; <BR>        es=pBlockTable-&gt;getAt (ACDB_MODEL_SPACE, pBlockTableRecord, <BR>                AcDb::kForWrite) ; <BR>        <BR>        if(es!=Acad::eOk)<BR>                acutPrintf("getAt faile!");<BR>        <BR>        pBlockTable-&gt;close () ;<BR>        AcDbObjectId newEntld;<BR>        pBlockTableRecord-&gt;appendAcDbEntity(newEntld,pBlkRef);<BR>        pBlockTableRecord-&gt;close();<BR>        pBlkRef-&gt;close();<BR>        <BR>}


为什么我调用了该函数,插入的图块显示不出来的,是什么原因!


谢谢

JA_JERRY 发表于 2005-2-20 16:22:00

我也是个菜鸟不知道我说的对不对,你的代码第一个if语句:


if(es==Acad::eOk)<BR>        {<BR>                AfxMessageBox("readDwgFile Successful!");<BR>                return;<BR>        }<BR>如果成功读入了ccd.dwg文件则readDwgFile的返回值是Acad::eOk,由于return 语句的作用是不是就退出了该函数,而后面的语句根本就没有执行,你把这个if语句删掉试试

zqljg 发表于 2005-2-20 16:54:00

不关上面的事,我把上面的屏蔽掉也是这个样了,还请大家帮一下忙!

easypower 发表于 2005-2-21 13:22:00

Acad::ErrorStatus es = Acad::eOk;<BR>        //获得数据库指定块的ID<BR>        AcDbBlockTable *pBTR;<BR>        es = pBackDb-&gt;getBlockTable(pBTR,AcDb::kForRead);<BR>        AcDbObjectId blkId;<BR>        es = pBTR-&gt;getAt(BlockId,blkId);<BR>        pBTR-&gt;close();<BR>        //将指定的块插入到一个新的数据库<BR>        AcDbDatabase *pNewDb = NULL;<BR>        es = pBackDb-&gt;wblock(pNewDb,blkId);<BR>        delete pBackDb;<BR>        //将新的数据库插入到当前数据库中形成一个新的块<BR>        AcDbObjectId newBlkId;<BR>        es = acdbCurDwg()-&gt;insert(newBlkId,BlockId,pNewDb,false);<BR>        delete pNewDb;

easypower 发表于 2005-2-21 13:24:00

把你


es = acdbHostApplicationServices()-&gt;workingDatabase()-&gt;insert (blockId, "myfile", pDwg, <BR>                Adesk::kFalse) ; <BR>        if ( es != Acad::eOk ) <BR>                acutPrintf ("\n插入块错误.") ; <BR>        delete pDwg ;


换成上面的,你自己再检查一下

jingelou 发表于 2005-2-22 15:33:00

你只是插入了块,还需要进行块引用


AcDbObjectId idBlock;                <BR>        AcDbBlockReference*       pBlock=new AcDbBlockReference;<BR>        pBlock-&gt;setPosition(ptCenter);<BR>        pBlock-&gt;setLayer(m_idLineLayer);<BR>        pBlock-&gt;setBlockTableRecord(idBlock);<BR>        pBlock-&gt;setScaleFactors(AcGeScale3d(m_dPlotScale));        <BR>        idArray.append(CLjDwg::AddEntity(pBlock));<BR>        pBlock-&gt;close();
页: [1]
查看完整版本: [ARX]大家帮忙看一下这段程序