Visual Basic Customization

Reply
Contributor
DLyaskov
Posts: 14
Registered: ‎06-24-2010
Message 1 of 6 (682 Views)
Accepted Solution

Problem with creating MLeader with the current MultiLeaderStyle settings

682 Views, 5 Replies
06-24-2010 12:56 PM

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

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 6 (677 Views)

Re: Problem with creating MLeader with the current MultiLeaderStyle settings

06-24-2010 02:50 PM 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
Contributor
DLyaskov
Posts: 14
Registered: ‎06-24-2010
Message 3 of 6 (664 Views)

Re: Problem with creating MLeader with the current MultiLeaderStyle settings

06-25-2010 05:57 PM 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

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 6 (660 Views)

Re: Problem with creating MLeader with the current MultiLeaderStyle settings

06-26-2010 04:24 AM 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
Contributor
DLyaskov
Posts: 14
Registered: ‎06-24-2010
Message 5 of 6 (645 Views)

Re: Problem with creating MLeader with the current MultiLeaderStyle settings

06-29-2010 06:24 AM in reply to: Hallex

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

Thank you.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 6 of 6 (644 Views)

Re: Problem with creating MLeader with the current MultiLeaderStyle settings

06-29-2010 07:15 AM in reply to: DLyaskov

Glad to help

Cheers :smileyhappy:

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community