Trying to set MLEADERSTYLE block name to 'TagCircle' or 'TagHexagon'

Trying to set MLEADERSTYLE block name to 'TagCircle' or 'TagHexagon'

christopher_benia
Explorer Explorer
577 Views
4 Replies
Message 1 of 5

Trying to set MLEADERSTYLE block name to 'TagCircle' or 'TagHexagon'

christopher_benia
Explorer
Explorer

Hello,

I am trying to set the MLEADERSTYLE content variable for 'Block' to the 'Circle' (with the Tag) or the 'Hexagon' (with the Tag) and I am having trouble. When I pull the information from a pre-existing style it returns '_TagCircle' or '_TagHexagon'. When I try to set a new style with these variables, I get a 'Key not found' error. I've tried the obvious play on words, no underscore, spaces, numbers like 0, 1, 2.

Does anyone know the name of those built in blocks we can use like: detail, hexagon, circle, etc?

Thanks in advance!

Chris

0 Likes
Accepted solutions (1)
578 Views
4 Replies
Replies (4)
Message 2 of 5

Ed__Jobe
Mentor
Mentor

Can you show your code? Use the </> button to put it in a code window.

 

Are you trying to define a style in a dwg that doesn't have them? When you start a new dwg from acad.dwt, the blocks haven't been created yet. The MLEASERSTYLE dialog creates the block the first time you specify a block to use for the style. Therefore I just import the styles from a template.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 5

christopher_benia
Explorer
Explorer

I understand now. When I was scanning an existing style, MLEADERSTYLE reported the block as "_TAGCIRCLE", but because the dialog didn't actually create the block and enter it into the drawing, the assignment in VBA was like a NULL reference (if you will). Once I add the block the error goes away, no surprise. I'll follow your suggestion and load from a template.

Thank you for the clarification.

0 Likes
Message 4 of 5

Ed__Jobe
Mentor
Mentor
Accepted solution

Here's my code for importing from a template.


Sub ImportMLeaderStyles()
    On Error GoTo Err_Control

    'Get/Set MultiLeaderStyles in current dwg
    Dim oDict As AcadDictionary
    Set oDict = ThisDrawing.Dictionaries.Item("ACAD_MLEADERSTYLE")
    Dim cDestMLStyles As New Collection
    Dim cSourceMLStyles As New Collection
    Dim oMLStyle As AcadMLeaderStyle
    Dim oDwg As AxDbDocument
    Set oDwg = AcadApplication.GetInterfaceObject("ObjectDBX.AxDbDocument.24")
    oDwg.xOpen "N:\Applications\AutoCAD\Map 2023\Template\_Engineering.dwt"
    Dim bTS As Boolean 'text style exists
    Dim oTS As AcadTextStyle
    Dim i As Integer
    
    'Check for text style required by mlstyle.
    For Each oTS In ThisDrawing.TextStyles
        If oTS.Name = "Simplex1" Then bTS = True
    Next
    If bTS = False Then
        Set oTS = ThisDrawing.TextStyles.Add("Simplex1")
        oTS.fontFile = "Simplex1.shx"
        ThisDrawing.ActiveTextStyle = oTS
    End If
    
    For i = 0 To oDict.Count - 1
        Dim oObj As AcadObject
        Dim bA As Boolean 'anno style exists
        Dim bS As Boolean 'standard style exists
        Set oObj = oDict.Item(i)
        If oObj.ObjectName = "AcDbMLeaderStyle" Then
            Set oMLStyle = oObj
            Select Case oMLStyle.Name
                Case Is = "GS_Annotative"
                    cDestMLStyles.Add oMLStyle, oMLStyle.Name
                    bA = True
                Case Is = "GS_Standard"
                    cDestMLStyles.Add oMLStyle, oMLStyle.Name
                    bS = True
            End Select
      End If
    Next i
    If bA = False Then
        Set oMLStyle = oDict.AddObject("GS_Annotative", "AcDbMLeaderStyle")
        cDestMLStyles.Add oMLStyle, oMLStyle.Name
    End If
    If bS = False Then
        Set oMLStyle = oDict.AddObject("GS_Standard", "AcDbMLeaderStyle")
        cDestMLStyles.Add oMLStyle, oMLStyle.Name
    End If
    
    'Get MultiLeaderStyles in source dwg
    Set oDict = oDwg.Dictionaries.Item("ACAD_MLEADERSTYLE")
    For i = 0 To oDict.Count - 1
      Set oObj = oDict.Item(i)
      If oObj.ObjectName = "AcDbMLeaderStyle" Then
          Set oMLStyle = oObj
          cSourceMLStyles.Add oMLStyle, oMLStyle.Name
      End If
    Next i
    CopyMLeaderStyle cSourceMLStyles("GS_Annotative"), cDestMLStyles("GS_Annotative")
    CopyMLeaderStyle cSourceMLStyles("GS_Standard"), cDestMLStyles("GS_Standard")
    
Cleanup:
    Set oDwg = Nothing
    Set oDbx = Nothing
    
Exit_Here:
    Exit Sub
Err_Control:
    Select Case Err.Number
    'Add your Case selections here
    'Case Is = 1000
        'Handle error
        'Err.Clear
        'Resume Exit_Here
    Case Else
        MsgBox Err.Number & ", " & Err.Description, , "ImportMLeaderStyles"
        Err.Clear
        Resume Exit_Here
    End Select
End Sub


Sub CopyMLeaderStyle(oSource As AcadMLeaderStyle, oDest As AcadMLeaderStyle)
    With oSource
        oDest.AlignSpace = .AlignSpace
        oDest.Annotative = .Annotative
        oDest.ArrowSize = .ArrowSize
'        oDest.ArrowSymbol = .ArrowSymbol
        oDest.BitFlags = .BitFlags
'        oDest.Block = .Block
        oDest.BlockColor = .BlockColor
        oDest.BlockConnectionType = .BlockConnectionType
        oDest.BlockRotation = .BlockRotation
        oDest.BlockScale = .BlockScale
        oDest.BreakSize = .BreakSize
        oDest.ContentType = .ContentType
        oDest.Description = .Description
        oDest.DoglegLength = .DoglegLength
        oDest.DrawLeaderOrderType = .DrawLeaderOrderType
        oDest.DrawMLeaderOrderType = .DrawMLeaderOrderType
        oDest.EnableBlockRotation = .EnableBlockRotation
        oDest.EnableBlockScale = .EnableBlockScale
        oDest.EnableDogleg = .EnableDogleg
        oDest.EnableFrameText = .EnableFrameText
        oDest.EnableLanding = .EnableLanding
        oDest.FirstSegmentAngleConstraint = .FirstSegmentAngleConstraint
        oDest.LandingGap = .LandingGap
        oDest.LeaderLineColor = .LeaderLineColor
        oDest.LeaderLineType = .LeaderLineType
'        oDest.LeaderLineTypeId = .LeaderLineTypeId
        oDest.LeaderLineWeight = .LeaderLineWeight
        oDest.MaxLeaderSegmentsPoints = .MaxLeaderSegmentsPoints
        oDest.Name = .Name
        oDest.ScaleFactor = .ScaleFactor
        oDest.SecondSegmentAngleConstraint = .SecondSegmentAngleConstraint
        oDest.TextAlignmentType = .TextAlignmentType
        oDest.TextAngleType = .TextAngleType
        oDest.TextColor = .TextColor
        oDest.TextHeight = .TextHeight
        oDest.TextLeftAttachmentType = .TextLeftAttachmentType
        oDest.TextRightAttachmentType = .TextRightAttachmentType
        oDest.TextString = .TextString
        oDest.TextStyle = .TextStyle
    End With

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 5

christopher_benia
Explorer
Explorer

This will help! Much appreciated!

0 Likes