明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1797|回复: 2

利用VBA 写文字 对齐方面疑问

[复制链接]
发表于 2011-10-11 21:30 | 显示全部楼层 |阅读模式
现在 我用 CAD VBA  写一个文字“--DK31+500"  ,插入到 坐标(100,100,0),即”--DK31+500“的左中 连到(100,100,0)点上, 代码写下

  1. Sub txt()
  2.     Dim mytxt As AcadTextStyle  
  3.     Dim ptinsert(2) As Double
  4.     Dim txtobj As AcadText
  5.         ptinsert(0) = 100: ptinsert(1) = 100: ptinsert(2) = 0
  6.     Set txtobj = ThisDrawing.ModelSpace.addtext("--DK31+500", ptinsert, 20)
  7.      txtobj.Alignment = acAlignmentMiddleLeft
  8. End Sub

运行代码后 , 竟然跑到 (0,0,0)这个点上啦, 如果把txtobj.Alignment = acAlignmentMiddleLeft 这行代码去掉,显示的是”--DK31+500“的左下角是(100,100,0),   我想让 这个文本的左中 对应的是坐标是(100,100,0) ,, 请高手看看,如何更改啊?
发表于 2011-10-11 23:08 | 显示全部楼层
本帖最后由 wylong 于 2011-10-11 23:13 编辑


  1. Sub txt()
  2.     Dim mytxt As AcadTextStyle
  3.     Dim ptinsert(2) As Double
  4.     Dim txtobj As AcadText
  5.    
  6.     ptinsert(0) = 100: ptinsert(1) = 100: ptinsert(2) = 0
  7.     Set txtobj = ThisDrawing.ModelSpace.AddText("--DK31+500", ptinsert, 20)
  8.    
  9.     txtobj.Alignment = acAlignmentMiddleLeft
  10.    
  11.     '加上下面此句即可
  12.     txtobj.TextAlignmentPoint = ptinsert
  13. End Sub

  14. '参见以下说明:
  15. '当 Alignment 属性设置为 acAlignmentLeft 时,该属性会自动复位为0, 0, 0,并且属性变为只读。
  16. '对齐到 acAlignmentLeft 的文字使用 InsertionPoint 属性来放置文字。
  17. '对齐到 acAlignmentAligned 或 acAlignmentFit 的文字同时使用 InsertionPoint 以及 TextAlignmentPoint 属性来放置文字。
  18. '对齐到其它任何位置的文字使用 TextAlignmentPoint 属性来放置文字。
 楼主| 发表于 2011-10-12 12:36 | 显示全部楼层
谢谢                  
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-4 03:54 , Processed in 0.185332 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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