- UID
- 1
- 积分
- 16111
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-3
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
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 |
|