VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with creating MLeader with the current MultiLeaderStyle settings

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
DLyaskov
1690 Views, 5 Replies

Problem with creating MLeader with the current MultiLeaderStyle settings

I am trying to create MLeader with the current MultiLeaderStyle settings, which is annotative. The code which I use is:

Private Sub onMLeader(strText As String, varP1 As Variant)

Dim varP2 As Variant

Dim objMLeader As AcadMLeader

Dim LeaderPoints(0 To 5) As Double

On Error GoTo Done

varP2 = ThisDrawing.Utility.GetPoint(varP1, "Select Second Leader Point: ")

LeaderPoints(0) = varP1(0)

LeaderPoints(1) = varP1(1)

LeaderPoints(2) = varP1(2)

LeaderPoints(3) = varP2(0)

LeaderPoints(4) = varP2(1)

LeaderPoints(5) = varP2(2)

Dim i As Long

Set objMLeader = ThisDrawing.ModelSpace.AddMLeader(LeaderPoints, i)

objMLeader.TextString = strText

objMLeader.Update

Exit Sub    'Exit now

Done:

    MsgBox Err.Description & vbCr & "MLeader Canceled!", vbCritical, "onMLeader()"

End Sub

My problem is that the resulting MLeaser is without landing(the properties of the Mleader shows length of the landing = 0) and the leader always starts from the left of the text, even if you start from the right, go horizontally to the left and the leader goes over the text. The strange thing is that the arrow head is correctly scaled, based on the currently selected annotative scale. If I grip the text and move it to the left and after that to the right the Mleader restores the landing, with its correct size from the MLeaderStyle  and the text is located correctly relative to the landing, but I don’t like to do that with every mleader. I can force the mleader to put landing to the Mleader object but it seems counterintuitive, since its suppose to use the current MLeaderStyle Settings, like VLisp does. I also can force the landing to change depending of the location of the first and the second leader point thru the Dogleg member but I had the side effect that the coordinates of the second leader point were changed, while I wanted to keep them unchanged, so that the landing starts from them and force the text to move to the left or right based on first leader point. It looks to me like VBA builds first the mleader with the text to the right of the second mleader point and after that flips the landing, not the text, if needed, changing that way the second (landing) leader point. I like to have my leader from starting at my first point and ending in my second point.

 

Its annoying that I go that behavior from VLisp with this single expression:

(COMMAND ".mleader" LEADER_START LEADER_END DIAMETER_TEXT) and I hoped to have something as simple as this.

 

Any suggestions or ideas how to build a MLeader with all the setting of the current MLeaderStyle, or what is wrong with my code will be greatly appreciated?

 

Thank you

5 REPLIES 5
Message 2 of 6
Hallex
in reply to: DLyaskov

Try this code

Option Explicit

Sub test()
Dim p1, p2
Dim vec(2) As Double
Dim pts(5) As Double
Dim i As Long
Dim util As AcadUtility
Dim space As AcadModelSpace
Dim ml As AcadMLeader
With ThisDrawing
Set util = .Utility
Set space = .ModelSpace
End With

Do While True
With util
p1 = .GetPoint(, vbCrLf & "Pick starting point:")
p2 = .GetPoint(p1, vbCrLf & "Pick ending point:")
pts(0) = p1(0): pts(1) = p1(1): pts(2) = p1(2)
pts(3) = p2(0): pts(4) = p2(1): pts(5) = p2(2)

End With
Set ml = space.AddMLeader(pts, i)
With ml
.ContentType = acMTextContent
If p2(0) > p1(0) Then
.TextJustify = acAttachmentPointMiddleLeft
vec(0) = 1: vec(1) = 0: vec(2) = 0
Else
vec(0) = -1: vec(1) = 0: vec(2) = 0
.TextJustify = acAttachmentPointMiddleRight
End If
.DogLegged = True
.DoglegLength = 0.09
.SetDoglegDirection i, vec
.TextLeftAttachmentType = acAttachmentBottomOfTopLine
.TextRightAttachmentType = acAttachmentBottomOfTopLine
.TextString = "First Line\PSecond Line"
End With
Loop

End Sub

 ~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 6
DLyaskov
in reply to: DLyaskov

Thank you for your response.

 

Your piece of code is very close to what I had in mind to do, but the annoying thing for which I was talking about, I mean the side effect, is when p1(0)>p2(0) then the leader is not build from p1 to p2 but it look like p2 is changed, in contrast of when p1(0) < p2(0) when the leader is exactly from p1 to p2. If you build two vertical lines and snap the mleader, once from left to right and second mleader from right to left you will see how when start from right and go to the left the mleader starts from the line and finishes at the second line (p1(0)<p2(0) case), but when you build you mleader from left to right (p1(0)>p2(0) case) your mleader line is pushed off the second line. Its annoying for me because when you build mleader thru autocad it does not behave that way.

 

Thank you for you code. I learned a lot programming from it.

Have a nice weekend

Message 4 of 6
Hallex
in reply to: DLyaskov

= How To Fix MLeader Second Point =

 

 Now the text is located correctly relative to the landing, anyway on my machine,

     not sure about if this code would be working correct with your variables and styles

     (tested on A2009 only)

  • 	Option Explicit
    
    Sub test()
    Dim p1, p2
    Dim vec(2) As Double
    Dim pts(5) As Double
    Dim leg As Double
    Dim i As Long
    Dim util As AcadUtility
    Dim space As AcadModelSpace
    Dim ml As AcadMLeader
    With ThisDrawing
    Set util = .Utility
    Set space = .ModelSpace
    End With
    
    leg = 0.0625 '<-- change to your suit
    
    On Error GoTo Err_Control
    
    Do While True
    
    With util
    p1 = .GetPoint(, vbCrLf & "Pick starting point (or hit Enter to Exit): ")
    p2 = .GetPoint(p1, vbCrLf & "Pick ending point: ")
    
    If p2(0) > p1(0) Then
    pts(0) = p1(0): pts(1) = p1(1): pts(2) = p1(2)
    pts(3) = p2(0): pts(4) = p2(1): pts(5) = p2(2)
    Else
    pts(0) = p1(0): pts(1) = p1(1): pts(2) = p1(2)
    pts(3) = p2(0): pts(4) = p2(1): pts(5) = p2(2)
    End If
    
    End With
    
    Set ml = space.AddMLeader(pts, i)
    
    With ml
    .ContentType = acMTextContent
    .DogLegged = True
    If p2(0) > p1(0) Then
    .TextJustify = acAttachmentPointMiddleLeft
    vec(0) = 1: vec(1) = 0: vec(2) = 0
    Else
    vec(0) = -1: vec(1) = 0: vec(2) = 0
    .TextJustify = acAttachmentPointMiddleRight
    End If
    
    .LandingGap = leg
    .SetDoglegDirection i, vec
    .DoglegLength = leg
    .TextLeftAttachmentType = acAttachmentBottomOfTopLine
    .TextRightAttachmentType = acAttachmentBottomOfTopLine
    .TextString = "First Line\PSecond Line"
    
    .SetLeaderLineVertices 0, pts ' <--fix the second point location
    
    .Update
    End With
    
    Loop
    
    Exit_Here:
    Exit Sub
    
    Err_Control:
    If Err.Description = "User input is keyword" Then
    Resume Exit_Here
    End If
    
    End Sub       
    

 

__________________________________________________________________

"The whole problem with the world is that fools and fanatics are always

so certain of themselves, and wiser people so full of doubts."

Bertrand Russell

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 5 of 6
DLyaskov
in reply to: Hallex

This solved the problem. Now Mleader behaves in the way you would expect.

Thank you.

Message 6 of 6
Hallex
in reply to: DLyaskov

Glad to help

Cheers Smiley Happy

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost