|
[code]
#define AOK(es) if(es != Acad::eOk) throw es;
void createHatch(void)
{
AcDbObjectId objId;
AcDbEntity* pEnt;
ads_name ent;
ads_point point;
if (RTNORM !=
acedEntSel(_T("SELECT AN ENTITY TO BE HATCHED: "),
ent,
point))
return;
assert(objId.setFromOldId(ent[0]));
AOK( acdbOpenObject(pEnt,objId,AcDb::kForRead) );
AcDbHatch *pHatch = new AcDbHatch;
assert(pHatch);
try
{
AcDbBlockTableRecordPointer pBtr(
ACDB_MODEL_SPACE,
curDoc()->database(),
AcDb::kForWrite);
AOK(pBtr.openStatus());
AOK(pHatch->setPatternAngle(0));
AOK(pHatch->setPatternScale(10));
AOK(pHatch->setAssociative(Adesk::kFalse));
AOK(pHatch->setPattern(AcDbHatch::kPreDefined,
_T("ANSI32")));
// append loop to hatch
AcDbObjectIdArray dbObjIds;
int objNum =
dbObjIds.append(pEnt->objectId());
acutPrintf(_T("\nOBJ number is %d."), objNum);
AOK(pHatch->appendLoop(AcDbHatch::kExternal,
dbObjIds));
AOK(pHatch->setLayer(pEnt->layer()));
AOK(pHatch->setColorIndex(256));
//bylayer
AOK(pHatch->setHatchStyle(AcDbHatch::kNormal));
AOK(pHatch->evaluateHatch());
AOK(pBtr->appendAcDbEntity(pHatch));
AOK(pHatch->close());
}
catch (const Acad::ErrorStatus es)
{
acutPrintf(_T("Error: %s"),
acadErrorStatusText(es));
delete pHatch;
}
[/code] |
|