- UID
- 69086
- 积分
- 178
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-8-1
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2003-8-8 18:12:44
|
显示全部楼层
修改至如此:
void AsdkMYH()
{
// TODO: Implement the command
AcDbHatch* pHatch = new AcDbHatch();
// Set hatch plane
//
AcGeVector3d normal(0.0, 0.0, 1.0);
pHatch->setNormal(normal);
pHatch->setElevation(0.0);
// Set hatch pattern to ANSI31 predefined type
//
pHatch->setPattern(AcDbHatch::kPreDefined, "ANSI31");
pHatch->setHatchStyle(AcDbHatch::kNormal);
pHatch->setPatternScale(0.5);
pHatch->setPatternAngle(0.0);
// Set Associativity
//
pHatch->setAssociative(Adesk::kFalse);
// Construct database AcDbLines
//
AcGePoint3d vertexPts[4];
AcDbObjectId lineId, hatchId;
AcDbObjectIdArray dbObjIds;
//AcDbLine *line=NULL;
vertexPts[0].set(2.0, 2.0, 0.0);
vertexPts[1].set(8.0, 2.0, 0.0);
vertexPts[2].set(8.0, 8.0, 0.0);
vertexPts[3].set(2.0, 8.0, 0.0);
for (int i = 0; i < 4; i++) {
AcDbLine *line = new AcDbLine(vertexPts,vertexPts[(i == 3) ? 0 : i+1]);
AcDbBlockTable* pBlkTbl;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,AcDb::kForRead);
AcDbBlockTableRecord* pBlkTblRcd;
pBlkTbl->getAt(ACDB_MODEL_SPACE,pBlkTblRcd,AcDb::kForWrite);
pBlkTbl->close();
pBlkTblRcd->appendAcDbEntity(lineId,line);
if(lineId.isNull()||!lineId.isValid())
{
acutPrintf("\nERROR!!Id is NULL!");
return;
}
pBlkTblRcd->close();
line->close();
dbObjIds.append(lineId);
}
int Idlen=dbObjIds.length();
acutPrintf("\ndbObjIds length:%d",Idlen);
// Append an external rectangular loop to hatch boundary
//
Acad::ErrorStatus es=pHatch->appendLoop(AcDbHatch::kExternal, dbObjIds);
if(es=Acad::eOk)
{
acutPrintf("\nappendLoop is ok");
}
else
{
acutPrintf("\nappendLoop is ERROR,Error No:%d",es);
pHatch->close();
return;
}
if (pHatch->evaluateHatch()!=Acad::eOk)
{
acutPrintf("\nevaluateHatch() is ERROR");
}
es=postToDb(pHatch);
if(es!=Acad::eOk)
{
acutPrintf("\npostToDb is ERROR,Error No:%d",es);
pHatch->close();
return;
}
pHatch->close();
}
但问题依旧,收到的id数组没有说错误,但如果他不出错误,总不会appendLoop函数本身错了吧?
还有一个类似的程序,检验appendLoop,程序如下,但问题时一样的不能appendLoop.这是怎么回事?(其中比例是实现手工获得的,保证每错误)
void Asdkfill()
{
// TODO: Implement the command
ads_name ss,entname;
AcDbObjectId objId;
AcDbEntity* pEnt=NULL;
AcDbObjectIdArray dbObjIds;
acedSSGet(NULL,NULL,NULL,NULL,ss);
long len;
acedSSLength(ss,&len);
for(long i=0;i<len;i++)
{
if(acedSSName(ss,i,entname)!=RTNORM)
{
acutPrintf("entname error,No:&ld",i);
return;
}
acdbGetObjectId(objId,entname);
if(objId.isNull()||!objId.isValid())
{
acutPrintf("\nERROR!!Id is NULL or invalid!");
return;
}
dbObjIds.append(objId);
}
AcDbHatch* pHatch = new AcDbHatch();
AcGeVector3d normal(0.0, 0.0, 1.0);
pHatch->setNormal(normal);
pHatch->setElevation(0.0);
pHatch->setPattern(AcDbHatch::kPreDefined, "ANSI31");
pHatch->setHatchStyle(AcDbHatch::kNormal);
pHatch->setPatternScale(10);
pHatch->setPatternAngle(0.0);
// Set Associativity
//
pHatch->setAssociative(Adesk::kFalse);
Acad::ErrorStatus es=pHatch->appendLoop(AcDbHatch::kExternal, dbObjIds);
if(es=Acad::eOk)
{
acutPrintf("\nappendLoop is ok");
}
else
{
acutPrintf("\nappendLoop is ERROR,Error No:%d",es);
pHatch->close();
return;
}
if (pHatch->evaluateHatch()!=Acad::eOk)
{
acutPrintf("\nevaluateHatch() is ERROR");
}
es=postToDb(pHatch);
if(es!=Acad::eOk)
{
acutPrintf("\npostToDb is ERROR,Error No:%d",acadErrorStatusText(es));
pHatch->close();
return;
}
pHatch->close();
int Idlen=dbObjIds.length();
acutPrintf("\ndbObjIds length:%d",Idlen);
}
剖面线填充的一个关键是:设置顺序问题
修改如下,则通过了:
AcDbHatch* pHatch = new AcDbHatch();
AcGeVector3d normal(0.0, 0.0, 1.0);
pHatch->setNormal(normal);
pHatch->setElevation(0.0);
pHatch->setAssociative(Adesk::kFalse);
pHatch->setPatternScale(2);
pHatch->setPatternAngle(0.0);
pHatch->setPattern(AcDbHatch::kPreDefined, "ANSI31");
pHatch->setHatchStyle(AcDbHatch::kNormal);
pHatch->appendLoop(AcDbHatch::kExternal,dbObjIds);
pHatch->evaluateHatch();
postToDb(pHatch);
pHatch->close();
供大家参考。 |
|