找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 585|回复: 0

[每日一码] 设置对齐标注的倾角为相对UCS X轴的绝对转角

[复制链接]

已领礼包: 13个

财富等级: 恭喜发财

发表于 2016-9-3 14:16:48 | 显示全部楼层 |阅读模式

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

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

×
Set oblique angle of aligned dimensions to a certain angle relative to an axis in the current UCS

Consider this: You want to set the oblique angle of an aligned dimension to an arbitrary value (for example, 30 degrees from the X-axis of the current UCS to one of the extension line within which the dimension is constructed).

To do this, you need to realize that that the Oblique angles are calculated relative to the line containing the two start points of the two extension lines of the dimension. Let's call this the base line of aligned dimensions. With this in mind, if the angle from the baseline to X axis is angBaselineToX, and the oblique angle relative to X axis will be angRelOblique, then (- angBaselineToX + angRelOblique) should be sent to AcDbAlignedDimension::oblique() as the input parameter. The following code does this:

  1. void setDimTxtOblique()
  2. {
  3. AcGePoint3d pt1, pt2;
  4. double baseAng, oblAng;
  5. AcGePoint3d ptDim;
  6. AcGeMatrix3d m;
  7. Acad::ErrorStatus es;
  8. int ret;

  9. AcDbDatabase *pDb =
  10.   acdbHostApplicationServices()->workingDatabase();

  11. // get start and end points
  12. if(acedGetPoint(NULL, L"\nFirst point: ",
  13.   asDblArray(pt1))!= RTNORM)
  14.   return;

  15. if( acedGetPoint(asDblArray(pt1), L"\nSecond point: ",
  16.   asDblArray(pt2) ) != RTNORM)
  17.   return;

  18. // get text position
  19. AcGePoint3d ptMid( 0.5*(pt1.x + pt2.x), 0.5*(pt1.y + pt2.y),
  20.   0.5*(pt1.z + pt2.z));
  21. if(acedGetPoint(asDblArray(ptMid), L"\nDim Line position:",
  22.   asDblArray(ptDim) ) != RTNORM)
  23.   return;

  24. // get the oblique angle from users
  25. // please note it's relative to the X axis of current UCS
  26. ret = acedGetAngle(NULL, L"Oblique angle: <0.0>", &oblAng);

  27. if( ret == RTNONE ) oblAng = 0.0;
  28. else if ( ret != RTNORM ) return;

  29. // calculate the dimension baseline angle
  30. baseAng = acutAngle(asDblArray(pt1), asDblArray(pt2));

  31. // create aligned dimension
  32. AcDbAlignedDimension* pDim = new AcDbAlignedDimension;
  33. es = pDim->setXLine1Point(pt1); assert(es==Acad::eOk);
  34. es = pDim->setXLine2Point(pt2); assert(es==Acad::eOk);

  35. // get transform matrix
  36. if( !acdbUcsMatrix(m, pDb) ) return;

  37. // set line points and text position as default
  38. es=pDim->setDimLinePoint(ptDim); assert(es==Acad::eOk);
  39. es=pDim->useDefaultTextPosition(); assert(es==Acad::eOk);
  40. es=pDim->setOblique(oblAng-baseAng); assert(es==Acad::eOk);

  41. // set default database and transform it to WCS
  42. pDim->setDatabaseDefaults();
  43. es = pDim->transformBy(m); assert(es==Acad::eOk);

  44. // append it to AutoCAD database
  45. AcDbBlockTableRecord *pBlkRec;
  46. AcDbObjectId objID;
  47. es = acdbOpenObject(pBlkRec, pDb->currentSpaceId(),
  48.   AcDb::kForWrite);
  49. assert(es==Acad::eOk);
  50. es =pBlkRec->appendAcDbEntity (objID, pDim) ;
  51. assert(es==Acad::eOk);
  52. // close it
  53. pDim->close();
  54. pBlkRec->close();

  55. return;
  56. }


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

本版积分规则

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

GMT+8, 2024-10-18 10:06 , Processed in 0.188948 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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