关于AcDbHatch的问题?
我是一个初学者,请各位帮我看一下,下面是画一个园,然后填充,程序编译通过,但运行时没有填充出来。void test()
{
ads_point pt1;
if(ads_getpoint(NULL,"\n请输入插入点:",pt1)!=RTNORM) return;
AcGePoint3d basePoint(pt1,pt1,pt1);
AcDbCircle *pCircle=new AcDbCircle;
pCircle->setCenter(basePoint);
pCircle->setRadius(1.5);
pCircle->setColorIndex(1); AcDbHatch* pHatch = new AcDbHatch();
AcGeVector3d normal(0.0, 0.0, 1.0);
pHatch->setNormal(normal);
pHatch->setElevation(0.0);
pHatch->setAssociative(Adesk::kTrue);
pHatch->setPattern(AcDbHatch::kPreDefined, "SOLID");
pHatch->setHatchStyle(AcDbHatch::kNormal);
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable,AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);
pBlockTable->close();
AcDbObjectId circleId;
AcDbObjectId hatchId;
AcDbObjectIdArray dbObjIds;
pBlockTableRecord->appendAcDbEntity(circleId,pCircle);
dbObjIds.setLogicalLength(0);
dbObjIds.append(circleId);
pHatch->appendLoop(AcDbHatch::kDefault, dbObjIds);
pHatch->evaluateHatch();
dbObjIds.setLogicalLength(0);
pHatch->getAssocObjIds(dbObjIds);
pBlockTableRecord->appendAcDbEntity(hatchId,pHatch);
pBlockTableRecord->close();
AcDbEntity *pEnt;
int numObjs = dbObjIds.length();
Acad::ErrorStatus es;
int i;
for (i = 0; i addPersistentReactor(hatchId);
pEnt->close();
}
}
pCircle->close();
pHatch->close();
} 最好用範圍來畫.
AcDbHatch* pHatch = new AcDbHatch();
AcGeVector3d normal(0.0, 0.0, 1.0);
pHatch->setNormal(normal);
pHatch->setElevation(0.0);
pHatch->setAssociative(Adesk::kFalse);
pHatch->setHatchStyle(AcDbHatch::kNormal);
pHatch->setPatternScale(10.0);
AcGePoint2dArray vertexPts;
AcGeDoubleArray vertexBulges;
vertexPts.setPhysicalLength(0).setLogicalLength(4);
vertexPts.set(m_d/2,0);
vertexPts.set(0,m_d/2);
vertexPts.set(0,0);
vertexPts.set(m_d/2,0);
vertexBulges.setPhysicalLength(0).setLogicalLength(4);
vertexBulges = 0.414;
vertexBulges = 0;
vertexBulges = 0;
vertexBulges = 0;
color.setColorIndex(150);
pHatch->setColor(color);
pHatch->appendLoop(AcDbHatch::kExternal, vertexPts, vertexBulges);
pHatch->setPattern(AcDbHatch::kUserDefined, "SOLID");
代替你畫的部分
非常感谢chang,但是我试了你提供的代码仍然没有填充出来,希望给出一段画一个园,并用solid填充的完整代码。 要想用其他的颜色填充怎么实现啊? 补充pHatch->updateOpen()在close()之前;
你的方法是hatch关联园的ID,但是园没有加到模型空间。也就是说没有ID.当然出现不了hatch。且要加到模型空间 你将我的hatch加到模型空间,就好了。
页:
[1]