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
以上红色语句不知为何不能设置居中,加入居中语句后文字会跑到老远的地方,这是为什么?请指教 |