AcDbHatch填充学习与求教
一般的外形用以下填充ARX程序可以成功看到填充出来的对象,但是我这个DWG上面的图用ARX填充看不到填充出来的实体。不知是哪里不对? 但是调用命令来填充时却可以。实在弄不懂,所以在这里请教一下咱们明经大侠了。代码如下:
填充涵数代码:
AcDbObjectId CreateHatch(AcDbObjectIdArray InIDList,bool CommandmodelPD/*=FALSE*/,ACHAR *cLayer/**//*="0"*/, ACHAR *cPattern/**//* = "SOLID"*/, int nColor/* = 256*/, double dAngle/* = 0.0*/, double dScale/* = 1.0*/)
{
AcDbObjectId DbOId,ObjID;
DbOId.setNull();
if (InIDList.length()==0)
{
return DbOId;
}
if (CommandmodelPD==FALSE)
{
AcCmColor CmC;
AcDbObjectIdArray DbOIdA ;
AcDbBlockTable * pDbBT;
AcDbBlockTableRecord * pDbBTR;
AcDbDatabase * pDbDatab = acdbHostApplicationServices()->workingDatabase();
AcGeVector3d normal(0.0, 0.0, 1.0);
DbOIdA=NULL;
for (int i=0;InIDList.length()>i;i++)
{
ObjID=InIDList.at(i);
if (ObjID.isErased()==TRUE)continue;
DbOIdA.append(ObjID);
}
AcDbHatch* pDbHat = new AcDbHatch();
pDbHat->setDatabaseDefaults();
pDbHat->setAssociative(Adesk::kTrue); //False填充线边界与填充不关连、TRUE填充边界线与填充对象关连,关连时,改边界线,填充跟随修改// BUG: doesn't do squat! have to set the reactor yourself to get associativity!
pDbHat->appendLoop(AcDbHatch::kExternal, DbOIdA);//添加外环边界实体,内环边界实体是AcDbHatch::kDefault
pDbHat->setPatternScale(dScale);//填充图的比例,控制图案的疏密程度
pDbHat->setPatternAngle(dAngle);//填充图的角度,控制图案的疏密程度
pDbHat->setPattern(AcDbHatch::kPreDefined, cPattern);
pDbHat->setNormal(normal);//填充区域的法向矢量设置
pDbHat->evaluateHatch(); //合成剖面线 crucial call or nothing gets displayed!
pDbDatab->getSymbolTable(pDbBT, AcDb::kForRead);
pDbBT->getAt(ACDB_MODEL_SPACE, pDbBTR, AcDb::kForWrite);
pDbBTR->appendAcDbEntity(DbOId, pDbHat);
pDbHat->setLayer(cLayer);
CmC.setColorIndex(nColor);
((AcDbEntity *)pDbHat)->setColor(CmC);
pDbBT->close();
pDbBTR->close();
pDbHat->close();
}else if (CommandmodelPD==TRUE)
{
ads_name Ename,SS;
acedSSAdd(NULL,NULL,SS);
for(int i=0;InIDList.length()>i;i++){
acdbGetAdsName(Ename,InIDList.at(i));
acedSSAdd(Ename,SS,SS);
}
acdbEntLast(Ename);
acdbGetObjectId(ObjID,Ename);
if (acedCommand(RTSTR,_T("-hatch"),RTSTR,_T("s"),RTPICKS,SS,RTSTR,_T(""),RTSTR,_T(""),0)==RTNORM)
{
acdbEntLast(Ename);
acdbGetObjectId(DbOId,Ename);
if (DbOId==ObjID)
{
DbOId.setNull();
}
}
acedSSFree(Ename);
acedSSFree(SS);
}
return DbOId;
}
测试代码:
ads_name Ename,SS;
ads_point p1;
AcDbObjectId Objid;
AcDbObjectIdArray IDList;
AcDbEntity *pEnt = NULL;
if (acedSSGet(NULL,NULL,NULL,NULL,SS)!=RTNORM)return;
long SSLen;
acedSSLength(SS,&SSLen);
for (int i=0;SSLen>i;i++)
{
acedSSName(SS,i,Ename);
acdbGetObjectId(Objid,Ename);
IDList.append(Objid);
}
CreateHatch(IDList);///第二个参数默认方式为FALSE说明使用ARX直接生成填充,如果为CreateHatch(IDList,TRUE);就是采用调 用命令生成填充对象 我对这个测试DWG分析了一上午,发现是因为图形里面有内环造成的。我把内环删除了可以用ARX填充生成。怎么让上面的ARX程序能区分内环还是外环呢?
页:
[1]