找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 2294|回复: 0

[图块] AcDbAttribute::setPosition() 似乎有问题,如何解决?

[复制链接]

已领礼包: 40个

财富等级: 招财进宝

发表于 2021-1-29 03:43:36 | 显示全部楼层 |阅读模式

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

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

×
AcDbAttribute::setPosition() function doesn't seem to function properly

问题:

I use following codes to set attribute postion
pAttdef->setHorizontalMode(AcDb::kTextCenter);
pAttdef->setVerticalMode(AcDb::kTextVertMid);
pAttdef->setAlignmentPoint(basePoint);

However the attribute text shows on origin st the beginning. when I move the blockreference a little bit the attrbute text comes back to the block center.

解答:

I understand what kind of problem that you're having. It has something to do
with the order of setting the AcDbAttribute members.

It is to my knowledge that you must use setAlignmentPoint() function AFTER
setPosition(), setHorizontalMode() and setVerticalMode() functions because the
alignmentPoint is relative to the other settings.
The following code snippet demonstrated how it works in that order.




  1. void testAttributeAlignment()
  2. {   
  3. AcDbEntity* pEnt = NULL;
  4. if(!getBlockReference(pEnt))
  5. //my own function to a pointer to an entity
  6. return;
  7. AcDbBlockReference *pBlkRef = AcDbBlockReference::cast(pEnt);
  8. AcDbAttribute *pAtt = NULL;
  9. AcDbObjectIterator *pAttIter = pBlkRef->attributeIterator();
  10. for (pAttIter->start(); !pAttIter->done(); pAttIter->step())
  11. {
  12. acdbOpenObject(pAtt, pAttIter->objectId(), AcDb::kForWrite);
  13. pAtt->setHorizontalMode(AcDb::kTextCenter);
  14. pAtt->setVerticalMode(AcDb::kTextVertMid);
  15. AcGePoint3d insertPt = pAtt->position();
  16. AcGePoint3d alignPt = pAtt->alignmentPoint();
  17. if(insertPt != alignPt)
  18. pAtt->setAlignmentPoint(insertPt);
  19. pAtt->close();
  20. }
  21. delete pAttIter;
  22. pBlkRef->close();
  23. }


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

本版积分规则

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

GMT+8, 2024-11-18 10:27 , Processed in 0.274099 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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