- UID
- 5043
- 积分
- 1347
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-5-13
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Creating a hatch object and setting its scale
Question
How do I create a hatch object and set its scale? I had a function in my ARX
application that was used to create HATCH pattern. However, I found that it was
useless to set scale in my application because I had to set the scale manually
once again in AutoCAD. Why did this happen?
Answer
This might be caused by the wrong placement of setPatternScale() function. Note
that you have to set hatch pattern properties, such as, pattern angle, pattern
scale, associativity, and pattern name just after AcDbHatch has been created.
After appending loops to the hatch object, you can set its other properties,
such as layer name, color index, hatch style and so on. Then evaluateHatch()
method must be used to evaluate if it can be properly displayed on the screen.
And lastly it should be appended to AutoCAD database and closed. The following
code shows how to do this exactly. For detailed information, refer to AcDbHatch
class explanation in ObjectARX documentation.
- #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("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, "ANSI32"));
- // append loop to hatch
- AcDbObjectIdArray dbObjIds;
- int objNum = dbObjIds.append(pEnt->objectId());
- acutPrintf("\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("Error: %s", acadErrorStatusText(es));
- delete pHatch;
- }
- }
|
|