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.