这并不完全是您所需要的,但可能会有帮助,我认为您可以在那里添加部分,以获得所需边缘上的第二个点,然后计算文本的旋转角度;J#039~
- Option Explicit
- Sub AddSomeLabel()
- Dim varPt As Variant
- Dim oPoly As AcadLWPolyline
- Dim oEnt As AcadEntity
- With ThisDrawing
- .Utility.GetEntity oEnt, varPt, "Select polyline (pick left point on the edge)"
- If TypeOf oEnt Is AcadLWPolyline Then
- Set oPoly = oEnt
- Else
- MsgBox "Wrong entity selected"
- Exit Sub
- End If
- Dim txtPt As Variant
- txtPt = PseudoCenter(oPoly)
- Dim oText As AcadMText
- Dim txtStr As String
- txtStr = "Blah\PBlah\PBlah"
- Dim pointUCS As Variant
- pointUCS = .Utility.TranslateCoordinates(txtPt, acUCS, acUCS, False)
- Set oText = MakeMText(pointUCS, txtStr)
- End With
- End Sub
- Function MakeMText(txtPt As Variant, strTxt As String) As AcadMText
- Dim oMText As AcadMText
- Dim oLine As AcadLine
- Set oMText = ThisDrawing.ModelSpace.AddMText(txtPt, 0#, strTxt)
- oMText.AttachmentPoint = acAttachmentPointMiddleCenter
- oMText.InsertionPoint = txtPt
- oMText.Update
- Set MakeMText = oMText
- End Function
- Function PseudoCenter(oPoly As AcadLWPolyline) As Variant
- Dim minPt As Variant
- Dim maxPt As Variant
- oPoly.GetBoundingBox minPt, maxPt
- Dim centPt(2) As Double
- centPt(0) = (minPt(0) + maxPt(0)) / 2
- centPt(1) = (minPt(1) + maxPt(1)) / 2
- centPt(2) = (minPt(2) + maxPt(2)) / 2
- PseudoCenter = centPt
- End Function
|