找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1111|回复: 0

[每日一码] 创建HATCH并设置比例

[复制链接]

已领礼包: 13个

财富等级: 恭喜发财

发表于 2016-8-14 19:00:03 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
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.

  1. #define AOK(es) if(es != Acad::eOk) throw es;
  2. void createHatch(void)
  3. {         
  4.             AcDbObjectId objId;
  5.             AcDbEntity* pEnt;
  6.             ads_name ent;
  7.             ads_point point;

  8.             if (RTNORM != acedEntSel("SELECT AN ENTITY TO BE HATCHED: ", ent,
  9. point))
  10.                         return;
  11.             assert(objId.setFromOldId(ent[0]));
  12.             AOK( acdbOpenObject(pEnt,objId,AcDb::kForRead) );

  13.             AcDbHatch *pHatch = new AcDbHatch;
  14.             assert(pHatch);
  15.             try
  16.             {
  17.                         AcDbBlockTableRecordPointer pBtr(ACDB_MODEL_SPACE,
  18. curDoc()->database(), AcDb::kForWrite);
  19.                         AOK(pBtr.openStatus());

  20.                         AOK(pHatch->setPatternAngle(0));
  21.                         AOK(pHatch->setPatternScale(10));
  22.                         AOK(pHatch->setAssociative(Adesk::kFalse));
  23.                         AOK(pHatch->setPattern(AcDbHatch::kPreDefined, "ANSI32"));

  24.                         // append loop to hatch
  25.                         AcDbObjectIdArray dbObjIds;
  26.                         int objNum = dbObjIds.append(pEnt->objectId());
  27.                         acutPrintf("\nOBJ number is %d.", objNum);
  28.                         AOK(pHatch->appendLoop(AcDbHatch::kExternal, dbObjIds));

  29.                         AOK(pHatch->setLayer(pEnt->layer()));
  30.                         AOK(pHatch->setColorIndex(256));     //bylayer
  31.                         AOK(pHatch->setHatchStyle(AcDbHatch::kNormal));
  32.                         AOK(pHatch->evaluateHatch());
  33.                         AOK(pBtr->appendAcDbEntity(pHatch));
  34.                         AOK(pHatch->close());
  35.             }
  36.             catch (const Acad::ErrorStatus es)
  37.             {
  38.                         acutPrintf("Error: %s", acadErrorStatusText(es));
  39.                         delete pHatch;
  40.             }
  41. }


论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-15 09:02 , Processed in 0.220329 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表