明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1591|回复: 3

为什么设置时文字对齐方式时,文字会跑了?

[复制链接]
发表于 2005-5-16 12:15:00 | 显示全部楼层 |阅读模式

Sub labelpnt()
Dim Ent As AcadBlockReference
Dim Height As Double
Dim pickedp1 As Variant
Dim pickedp2 As Variant
Dim OffsetValue As Double
Dim MidPos(0 To 2) As Double
Dim FromPnt, Topnt As Variant
Dim ppt As Variant
Dim NoObj As AcadText
Dim ElevObj As AcadText
Dim line1 As AcadLine
Dim line2 As AcadLine
Dim Group1 As AcadGroup
Dim objgroup(0 To 3) As AcadEntity

Dim sPnt As Variant
Dim ePnt As Variant
Const pi = 3.1415926
On Error Resume Next

RETRY:

Call ThisDrawing.Utility.GetEntity(Ent, pnt, vbCrLf & "选符号...")
If Err Then
Err.Clear
End
End If

LblLen = 5
Height = 1
OffsetValue = 0.5

FromPnt = Ent.InsertionPoint
Topnt = ThisDrawing.Utility.GetPoint(FromPnt, "指定标注位置...")
If Err <> 0 Then
Err.Clear
Exit Sub
End If

Set line1 = ThisDrawing.ModelSpace.AddLine(FromPnt, Topnt)

If pd(FromPnt, Topnt) = True Then
ppt = ThisDrawing.Utility.PolarPoint(Topnt, pi, LblLen)
Else
ppt = ThisDrawing.Utility.PolarPoint(Topnt, 0, LblLen)
End If

Set line2 = ThisDrawing.ModelSpace.AddLine(Topnt, ppt)

sPnt = line2.StartPoint
ePnt = line2.EndPoint

'''Ï中点坐标
MidPos(0) = (sPnt(0) + ePnt(0)) / 2
MidPos(1) = (sPnt(1) + ePnt(1)) / 2
MidPos(2) = 0

'''文字注记位置
pickedp1 = ThisDrawing.Utility.PolarPoint(MidPos, pi / 2, OffsetValue)
pickedp2 = ThisDrawing.Utility.PolarPoint(MidPos, 0 - pi / 2, Height + OffsetValue)

'''标注文字
Set NoObj = ThisDrawing.ModelSpace.AddText("JS121", pickedp1, Height)
'''以下这句总不对

NoObj.Alignment = acAlignmentCenter

'''文字
Set ElevObj = ThisDrawing.ModelSpace.AddText("2.12", pickedp2, Height)
NoObj.Alignment = acAlignmentCenter

'''¶ÔÏó±à×é
Set objgroup(0) = line1
Set objgroup(1) = line2
Set objgroup(2) = NoObj
Set objgroup(3) = ElevObj
Set Group1 = ThisDrawing.Groups.Add("*")
Group1.AppendItems objgroup
GoTo RETRY

End Sub
Function pd(p1 As Variant, p2 As Variant) As Boolean
If p1(0) > p2(0) Then
pd = True
Else
pd = False
End If
End Function
以上红色语句不知为何不能设置居中,加入居中语句后文字会跑到老远的地方,这是为什么?请指教
发表于 2005-5-16 17:38:00 | 显示全部楼层
在另外一贴我已经回复了,你去看一下.
发表于 2005-5-16 18:41:00 | 显示全部楼层
NoObj.Alignment = acAlignmentCenter '后加下语句 NoObj.TextAlignmentPoint = pickedp2
 楼主| 发表于 2005-5-16 19:32:00 | 显示全部楼层
我试出来了,谢谢大家。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-27 16:36 , Processed in 0.145092 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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