Hi @Anonymous . The error message is saying it is having trouble with the portion of your one line of code, where it is trying to retrieve a balloon style. Is there a copy of that specifically named style in your local document, or is it only present in the global/external style library? You may need make sure the style is copied from the style library to your local document, before trying to assign it to objects in your drawing like this.
Also, I noticed that your line of code which is trying to set the dimension style by name, is missing a letter at the end of one of the words. "oStyles.DimensionStyle.Item("DC-STD_Dim")" is missing the "s" at the end of DimensionStyle(s), so it should be oStyles.DimensionStyles.Item("DC-STD_Dim"). The same goes for making sure the dimension style is available locally in the document.
Try this code, and see if it works any better for you:
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oStyles As DrawingStylesManager = oDrawDoc.StylesManager
'name of the balloon style
Dim oBStyleName As String = "DC-STD_Ballon"
'name of the dimesion style
Dim oDStyleName As String = "DC-STD_Dim"
Dim oMyBStyle As BalloonStyle
For Each oBStyle As BalloonStyle In oStyles.BalloonStyles
If oBStyle.Name = oBStyleName Then
oMyBStyle = oBStyle.ConvertToLocal
End If
Next
If oMyBStyle Is Nothing Then
MsgBox("Couldn't find a balloon style named '" & oBStyleName & "'. Exiting.", , "")
Exit Sub
End If
Dim oMyDimStyle As DimensionStyle
For Each oDStyle As DimensionStyle In oStyles.DimensionStyles
If oDStyle.Name = oDStyleName Then
oMyDimStyle = oDStyle.ConvertToLocal
End If
Next
If oMyDimStyle Is Nothing Then
MsgBox("Couldn't find a dimension style named '" & oDStyleName & "'. Exiting.", , "")
Exit Sub
End If
Dim oSheet As Sheet
Dim oBalloon As Balloon
Dim oDrawingDim As DrawingDimension
For Each oSheet In oDrawDoc.Sheets
'change ballons
For Each oBalloon In oSheet.Balloons
Try
oBalloon.Style = oMyBStyle
Catch
MsgBox("Failed to set balloon style.",,"")
End Try
Next
' Iterate over all dimensions in the drawing and change style
For Each oDrawingDim In oSheet.DrawingDimensions
Try
oDrawingDim.Style = oMyDimStyle
Catch
MsgBox("Failed to set dimension style.",,"")
End Try
Next
Next
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS
Wesley Crihfield

(Not an Autodesk Employee)