找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1115|回复: 3

[分享]:获得 Text 的“真实”的宽度...

[复制链接]

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-9-18 13:20:15 | 显示全部楼层 |阅读模式

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

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

×
How to get the actual width of a text string using VBA?  
ID    65788  
Applies to:    AutoCAD 2000
AutoCAD 2000I
AutoCAD 2002

Date    7/23/2002  

This document is part of   Visual Lisp   Text, Mtext   VBA   


Question
I do not see a property of the MText object that will return the actual string
width. The GetBoundingBox method returns values based on the bounding box of
the MText object, not the actual text string.
Answer
The MText object does not have a property that returns the width of the actual
text string. As a potential work around, you can get the Width value from DXF
group code 42 of the object. Below is a Lisp routine and a VBA procedure.  To
use this example, load the Lisp routine before running the VBA procedure.

The Lisp code will add a command named myMTextWidth. The VBA procedure adds
MText to the current drawing, and then it runs the Lisp code, using SendCommand.
The Lisp code gets the width of the last entity (the MText) and puts the value
in the USERR1 system variable. The VBA procedure retrieves this value, and prints
it in the 'Immediate' window (Ctrl+G in the VBA IDE).


(defun c:myMTextWidth ( )
   (setq ent (entlast))
   (setq entdata (entget ent))
   (setq tHeight(cdr (assoc 42 entdata)))
   (setvar "USERR1" tHeight)
   (princ)
   (princ)
)



Sub testMtextHeight()
' This example creates an MText object in model space.


   Dim MTextObj As AcadMText
   Dim corner(0 To 2) As Double
   Dim width As Double
   Dim text As String


   corner(0) = 0#: corner(1) = 10#: corner(2) = 0#
   width = 1
   text = "This test 11111111111"
   ' Creates the mtext Object
   Set MTextObj = ThisDrawing.ModelSpace.AddMText(corner, width, text)


   ' ZoomAll
   ThisDrawing.SendCommand "MyMTextWidth "


   Debug.Print ThisDrawing.GetVariable("Userr1")


End Sub
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
发表于 2002-10-30 21:21:30 | 显示全部楼层
我的办法是:把字串设置成某种对齐方式,去两个夹点间的坐标差值即可。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 181个

财富等级: 日进斗金

发表于 2002-11-11 09:31:25 | 显示全部楼层
对于单行文字,可以用GetBoundingBox获取,但有条件,文字必须是水平的,并且不能用ScaleFactor设置比例因子。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2009-6-18 14:30:30 | 显示全部楼层
用lisp的话,是用本身提供的一个函数就可以
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-5-3 06:14 , Processed in 0.443871 second(s), 37 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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