找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 146|回复: 0

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

[复制链接]

0

主题

0

回帖

28

积分

管理员

积分
28
发表于 2024-3-14 19:35:22 | 显示全部楼层 |阅读模式
  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. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2024-12-29 04:48 , Processed in 0.128697 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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