Jump to content

Recommended Posts

Posted

How to rotate leader's text with VBA, and how to set the rotation angle in the model space (by clicking)?

 

Public Sub Leader()
Dim dblPoints(5) As Double
Dim varStartPoint As Variant
Dim varEndPoint As Variant
Dim intLeaderType As Integer

Dim objAcadLeader As AcadLeader
Dim objAcadMtext As AcadMText
Dim strMtext As String
Dim intI As Integer
intLeaderType = acLineWithArrow
varStartPoint = ThisDrawing.Utility.GetPoint(, "Select leader start point: ")
varEndPoint = ThisDrawing.Utility.GetPoint(varStartPoint, "Select leader end point: ")
For intI = 0 To 2
dblPoints(intI) = varStartPoint(intI)
dblPoints(intI + 3) = varEndPoint(intI)
Next
strMtext = InputBox("Notes:", "Leader Notes")
If strMtext = "" Then Exit Sub
' Create the text for the leader
Set objAcadMtext = ThisDrawing.ModelSpace.AddMText(varEndPoint, Len(strMtext) * ThisDrawing.GetVariable("dimscale"), strMtext)
' Flip the alignment direction of the text
If varEndPoint(0) > varStartPoint(0) Then
objAcadMtext.AttachmentPoint = acAttachmentPointMiddleLeft
Else
objAcadMtext.AttachmentPoint = acAttachmentPointMiddleRight
End If
objAcadMtext.InsertionPoint = varEndPoint
'Create the leader object
Set objAcadLeader = ThisDrawing.ModelSpace.AddLeader(dblPoints, objAcadMtext, intLeaderType)
objAcadLeader.Update
End Sub

Posted

Try this

Option Explicit
Public Sub Leader()
Dim Util As AcadUtility
Dim dblPoints(5) As Double
Dim varStartPoint As Variant
Dim varEndPoint As Variant
Dim intLeaderType As Integer
Dim objAcadLeader As AcadLeader
Dim objAcadMtext As AcadMText
Dim strMtext As String
Dim intI As Integer
Dim ang As Double
' Get utility object
Set Util = ThisDrawing.Utility
intLeaderType = acLineWithArrow
varStartPoint = ThisDrawing.Utility.GetPoint(, "Select leader start point: ")
varEndPoint = ThisDrawing.Utility.GetPoint(varStartPoint, "Select leader end point: ")
For intI = 0 To 2
dblPoints(intI) = varStartPoint(intI)
dblPoints(intI + 3) = varEndPoint(intI)
Next
strMtext = InputBox("Notes:", "Leader Notes")
If strMtext = "" Then Exit Sub
' Create the text for the leader
Set objAcadMtext = ThisDrawing.ModelSpace.AddMText(varEndPoint, Len(strMtext) * ThisDrawing.GetVariable("dimscale"), strMtext)
' Flip the alignment direction of the text
If varEndPoint(0) > varStartPoint(0) Then
objAcadMtext.AttachmentPoint = acAttachmentPointMiddleLeft
Else
objAcadMtext.AttachmentPoint = acAttachmentPointMiddleRight
End If
objAcadMtext.InsertionPoint = varEndPoint
'Create the leader object
Set objAcadLeader = ThisDrawing.ModelSpace.AddLeader(dblPoints, objAcadMtext, intLeaderType)
' Get angle
ang = Util.GetAngle(varEndPoint, vbCrLf & "Specify direction >>")
' Rotate mtext
objAcadMtext.Rotation = ang
objAcadLeader.Update
End Sub

 

~'J'~

  • 3 years later...
Posted

i have this code, and i wanna to rotated text.

maybe anyone can help me. thanks :)

 

 

Sub Xxxx()

Dim ACAD As AcadApplication

Dim txObj As acadText

Dim ws As Range

Dim CrdNo(0 To 2) As Double

Dim TxNo As String

Dim hNo As Double

Dim LastRow As Double

Dim i As Integer

Dim j As Integer

Dim k As Integer

Set ACAD = GetObject(, "AutoCAD.Application")

Set ws = Worksheets("NUM").Cells

LastRow = ws(Rows.Count, 20).End(xlUp).Row

hNo = 0.3

For i = 2 To LastRow

j = 20

CrdNo(0) = ws(i, j): CrdNo(1) = ws(i, j + 1): CrdNo(2) = "0"

TxNo = ws(i, j)

Set txObj = ACAD.ActiveDocument.ModelSpace.AddText(TxNo, CrdNo, hNo)

Next i

End Sub

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...