[求助]wblock的问题
假设下面将数组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 编辑
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没有创建,所以死机。
还有你的代码很不规范,注意养成良好的代码书写格式和合理的容错处理。 不是你说的问题。
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空引用。莫名其妙。 也是一头雾水
页:
[1]