明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2362|回复: 3

[求助]wblock的问题

[复制链接]
发表于 2011-5-24 11:06:02 | 显示全部楼层 |阅读模式
假设下面将数组idarr成功填充
for (pltr->start();!pltr->done();pltr->step())
    {
     AcDbEntity *nEntity ;
     ErrorStatus es = pltr->getEntity(nEntity,AcDb::kForRead);
     if (nEntity->layerId() == bulidLID || nEntity->layerId() == splitLID ||  nEntity->layerId() == bulidSymLID ||  nEntity->layerId()  == splitSymLID)
     {
      idarr.append(nEntity->id());
      AcDbLine *line = AcDbLine::cast(nEntity);
      if (line != NULL)
      {
       x += line->startPoint().x;
       x += line->endPoint().x;
       y += line->startPoint().x;
       y += line->endPoint().x;
       i++;
      }
     }
     nEntity->close();
    }
那么本段代码


const ACHAR * filea= _T("Save");
resbuf *result = ads_newrb(RTSTR);
int iflags=ads_getfiled(filea, NULL, _T("dwg"), 33, result);

  for (int i = 0 ;i<idarr.length();i++)
  {
   AcDbObject *DbObject;
   ErrorStatus es = acdbOpenObject(DbObject,idarr.at(i),AcDb::kForWrite);
   if (es != eOk)
    AfxMessageBox(_T("XX"));
   DbObject->close();
  }
  ACHAR *FileName;
     if (iflags==RTNORM)
        {
   FileName = (ACHAR*)malloc(sizeof(result->resval.rstring));
   StrCpy(FileName,result->resval.rstring);
   AcDbDatabase * pdb;
   AcGePoint3d pt3d(x / i,y / i,0);
   if (idarr.isEmpty())
   {
    acedAlert(_T("实体数组中未包含任何实体!"));
    return;
   }
   AcDbDatabase *db = acdbHostApplicationServices()->workingDatabase();
   ErrorStatus es = db->wblock(pdb,idarr,pt3d);                                                      //执行到这里会报错
   if (es != Acad::eOk)
   {
     acedAlert(_T("wblock操作失败!"));
     return;
   }
   es =  pdb->saveAs(FileName);
   delete pdb;
   //free(FileName);
  }

这是怎么回事?


发表于 2011-5-26 10:39:24 | 显示全部楼层
本帖最后由 松竹 于 2011-5-26 10:39 编辑

Acad::ErrorStatus

wblock(

AcDbDatabase*& pOutputDb,

const AcDbObjectIdArray& outObjIds,

const AcGePoint3d& basePoint);

pOutputDb Returns pointer to the database that was written to
outObjIds Input array of objectId entities of all objects to be wblocked out
basePoint Input base point (in WCS coordinates for pOutputDb) to be used in pOutputDb

Creates a new AcDbDatabase object, sets pOutputDb to point to it, and then uses the wblockClone mechanism to write the array of objects specified by outObjId entities out to the Model Space block table record of the database pointed to by pOutputDb, using basePoint as the base point value for pOutputDb.

The calling application is responsible for deallocating (via the C++ delete operator) the AcDbDatabase object that pOutputDb is set to point to.

Returns Acad::eOk if operation is successful.

See the BASE command documentation in the AutoCAD online help for more information on base point.

这里面写的很清楚,你的pdb没有创建,所以死机。
还有你的代码很不规范,注意养成良好的代码书写格式和合理的容错处理。
 楼主| 发表于 2011-5-30 13:42:42 | 显示全部楼层
不是你说的问题。

                const ACHAR * filea= _T("Save");
        resbuf *result = ads_newrb(RTSTR);
        int iflags=ads_getfiled(filea, NULL, _T("dwg"), 33, result);


                AcDbDatabase * pdb1;
                AcDbDatabase *db1 = acdbHostApplicationServices()->workingDatabase();
                AcGePoint3d pt3d1(x / i,y / i,0);
                ErrorStatus es1 = db1->wblock(pdb1,idarr,pt3d1);
                pdb1->saveAs(result->resval.rstring);
这样写为什么就正常?我现在都没弄清楚到底是怎么回事。报的错误有时候说缓存满,有时候说CAD空引用。莫名其妙。
发表于 2011-7-13 14:31:24 | 显示全部楼层
也是一头雾水
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-29 03:40 , Processed in 0.174170 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表