wmz 发表于 2004-11-25 13:11:00

[VBA]请教mccad老师关于写文字等几个问题

mccad老师:您好!现有几个问题请教:
1,写文字的对齐方式(我以前看过这方面的书,忘记了,这书又被别人借走了)和写文字的方向(朝向),如我设定: Txtobj.Rotation=45,但却得到的文字是以文字串的左下角为基点旋转了45度,那么,我如何做到以文字串的中心点进行旋转呢?
2,字体设置:用txtobj.setfont方法如何设定ACAD字体?如我要设定:txtobj.setfont "宋体",false,false,1,1 没问题;但我如果设定:TxtObj.setfont "rs", false,false,1,1 就不行了,而不得不这样设定:TxtObj.FontFile "c:\acad2002\fonts\rs.shx",这样一来,问题又来了:如若ACAD2002安装在别的盘和别的文件夹,就很不方便了,这怎样解决?
3,VBA怎样写扩展数据,如我写了文字和插入了图块,要向它们加入扩展数据,该怎样办?
以上问题,务请mccad老师不吝赐教!

王咣生 发表于 2004-11-25 21:12:00

(1) 理解这段内容:
Remarks Text aligned to acAlignmentLeft uses the InsertionPoint property to position the text.
文字对齐方式为acAlignmentLeft(默认值)的,直接用InsertionPoint属性改变文字位置;
Text aligned to acAlignmentAligned, or acAlignmentFit uses both the InsertionPoint and TextAlignmentPoint properties to position the text.
文字对齐方式为acAlignmentAligned或acAlignmentFit的,要用InsertionPoint和TextAlignmentPoint改变其位置.
Text aligned to any other position uses the TextAlignmentPoint property to position the text.
若文件采用其它的对齐方式,用TextAlignmentPoint改变其位置.
Sub Example_TextAlignmentPoint()
                       Dim textObj As AcadText
                       Dim textString As String
                       Dim insertionPoint(0 To 2) As Double
                       Dim height As Double
                       
                       textString = "Hello, World."
                       insertionPoint(0) = 10: insertionPoint(1) = 10: insertionPoint(2) = 0
                       height = 0.5
                       
                       Set textObj = ThisDrawing.ModelSpace.AddText(textString, insertionPoint, height)
                       
                       Dim alignmentPoint(0 To 2) As Double
                       alignmentPoint(0) = 100: alignmentPoint(1) = 100: alignmentPoint(2) = 0
                       
                       textObj.Alignment = acAlignmentMiddleCenter                               '改变文字对齐位置
                       textObj.TextAlignmentPoint = alignmentPoint
                       textObj.Rotation = 1.57
                       ZoomExtents
                       
End Sub
(2) FontFile方法
Sub Example_FontFile()
                       Dim textStyle1 As AcadTextStyle
                       Dim newFontFile As String
                       
                       Set textStyle1 = ThisDrawing.ActiveTextStyle
                       ' Change the value for FontFile
                       newFontFile = "romant.shx"
                       textStyle1.fontFile = newFontFile
                       
End Sub
直接写"romant.shx"就可以了,只要它在AutoCAD搜索路径下.
(3) 扩展数据
用SetXData方法. 任何数据都可以加扩展数据,图块也不例外.

wmz 发表于 2004-11-26 19:22:00

谢谢了!前两个问题基本弄清了.第三个问题:这SetxData方法的具体实现?

mccad 发表于 2004-11-26 21:10:00

看看SetXData方法的例子就可以明白。

wmz 发表于 2004-11-27 13:24:00

可是,我手头没有SetXData方法的例子的资料呀.我在本站搜索,结果如下:
查询条件:SetXData 在所有分类的所有专题中 没有或没有找到任何文章

wmz 发表于 2004-11-27 14:52:00

找到了,问题解决了,谢谢两位!
---闹半天,在本站的"对象模型"中.

birdsky 发表于 2007-12-11 13:02:00

跟着楼主学习了,长见识:)

兰州人 发表于 2007-12-12 17:37:00

SetXData
Common AcadObject Methods-----通用AcadObject方法
SetXData Sets the extended data (XData), that is, instance-specific data associated
with an object. Parameters: XDataType As Variant (array of
Integers) and XDataValue As Variant (array of Variants).
SetXData集扩展数据(XData)--与物体数据关联,参数XDataType变量(整型数组)XDataValue数据变量。
页: [1]
查看完整版本: [VBA]请教mccad老师关于写文字等几个问题