明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1874|回复: 2

急!VBA中插入的文字对正方式为“中”的命令是什么啊?

[复制链接]
发表于 2008-6-13 10:18:00 | 显示全部楼层 |阅读模式

我用VBA写的小程序,在CAD图形中插入一行文字,但是文字都是居左对正,请问如何能把文字设置成居中对正啊?

我指的是文字居中对正的代码怎么写的啊?谢谢各位指点!

发表于 2008-6-14 09:32:00 | 显示全部楼层
文档里面的例子

Sub Example_Alignment()
' This example creates a text object in model space and
' demonstrates setting the alignment of the new text string

Dim textObj As AcadText
Dim textString As String
Dim insertionPoint(0 To 2) As Double, alignmentPoint(0 To 2) As Double
Dim height As Double
Dim oldPDMODE As Integer
Dim pointObj As AcadPoint

' Define the new Text object
textString = "Hello, World."
insertionPoint(0) = 3: insertionPoint(1) = 3: insertionPoint(2) = 0
alignmentPoint(0) = 3: alignmentPoint(1) = 3: alignmentPoint(2) = 0
height = 0.5

' Create the Text object in model space
Set textObj = ThisDrawing.ModelSpace.AddText(textString, insertionPoint, height)

oldPDMODE = ThisDrawing.GetVariable("PDMODE") ' Record existing point style

' Create a crosshair over the text alignment point
' to better visualize the alignment process
Set pointObj = ThisDrawing.ModelSpace.AddPoint(alignmentPoint)

ThisDrawing.SetVariable "PDMODE", 2 ' Set point style to crosshair

ThisDrawing.Application.ZoomAll

' Set the text alignment to a value other than acAlignmentLeft, which is the default.
' Create a point that will act as an alignment reference point
textObj.Alignment = acAlignmentRight

' Create the text alignment reference point and the text will automatically
' align to the right of this point, because the text
' alignment was set to acAlignmentRight
textObj.TextAlignmentPoint = alignmentPoint
ThisDrawing.Regen acActiveViewport
MsgBox "The Text object is now aligned to the right of the alignment point"

' Center the text to the alignment point
textObj.Alignment = acAlignmentCenter
ThisDrawing.Regen acActiveViewport
MsgBox "The Text object is now centered to the alignment point"

' Reset point style
ThisDrawing.SetVariable "PDMODE", oldPDMODE
End Sub
发表于 2008-6-14 15:51:00 | 显示全部楼层
楼上正解,个人觉得对齐方式修改为“中”后,可以把pointObj删除。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-29 21:51 , Processed in 0.228193 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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