Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Andrii 

 

the code below used to work by giving a list of the available styles but i would like to specify the style by name and not pick from a list

 

where / what would I change 

 

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing document must be active for this code to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisDoc.Document
	Dim oSMgr As DrawingStylesManager = oDDoc.StylesManager
	Dim oSSNames As New List(Of String)
	For Each oSS As DrawingStandardStyle In oSMgr.StandardStyles
		oSSNames.Add(oSS.Name)
	Next
	Dim oSSName As String = InputListBox("Choose Standard Style For Active Sheet", oSSNames)
	If oSSName = "" Then Exit Sub
	Dim oDSS As DrawingStandardStyle = oSMgr.StandardStyles.Item(oSSName)
	Dim oSheet As Sheet = oDDoc.ActiveSheet
	SetSheetStandardStyle(oSheet, oDSS)
	If oDDoc.RequiresUpdate Then oDDoc.Update2(True)
	'If oDDoc.Dirty Then oDDoc.Save
End Sub


Sub SetSheetStandardStyle(oSheet As Sheet, oDSS As DrawingStandardStyle)
	If IsNothing(oSheet) Or IsNothing(oDSS) Then Exit Sub
	Dim oDStyles As ObjectDefaultsStyle = oDSS.ActiveObjectDefaults
	Dim oDDims As DrawingDimensions = oSheet.DrawingDimensions
	Dim oGDims As GeneralDimensions = oDDims.GeneralDimensions
	For Each oGDim As GeneralDimension In oGDims : oGDim.Style = oDStyles.LinearDimensionStyle : Next
	Dim oODims As OrdinateDimensions = oDDims.OrdinateDimensions
	For Each oODim As OrdinateDimension In oODims : oODim.Style = oDStyles.OrdinateDimensionStyle : Next
	Dim oODSs As OrdinateDimensionSets = oDDims.OrdinateDimensionSets
	For Each oODS As OrdinateDimensionSet In oODSs : oODS.Style = oDStyles.OrdinateSetDimensionStyle : Next
	Dim oCDSs As ChainDimensionSets = oDDims.ChainDimensionSets
	For Each oCDS As ChainDimensionSet In oCDSs : oCDS.Style = oDStyles.ChainDimensionStyle : Next
	Dim oBDSs As BaselineDimensionSets = oDDims.BaselineDimensionSets
	For Each oBDS As BaselineDimensionSet In oBDSs : oBDS.Style = oDStyles.BaselineDimensionStyle : Next
	Dim oDNotes As DrawingNotes = oSheet.DrawingNotes
	Dim oCNs As ChamferNotes = oDNotes.ChamferNotes
	For Each oCN As ChamferNote In oCNs : oCN.DimensionStyle = oDStyles.ChamferNoteStyle : Next
	Dim oGNs As GeneralNotes = oDNotes.GeneralNotes
	For Each oGN As GeneralNote In oGNs : oGN.TextStyle = oDStyles.GeneralNoteStyle : Next
	Dim oHTNs As HoleThreadNotes = oDNotes.HoleThreadNotes
	For Each oHTN As HoleThreadNote In oHTNs : oHTN.Style = oDStyles.HoleNoteStyle : Next
	Dim oLNs As LeaderNotes = oDNotes.LeaderNotes
	For Each oLN As LeaderNote In oLNs : oLN.DimensionStyle = oDStyles.LeaderTextStyle : Next
	Dim oPNs As PunchNotes = oDNotes.PunchNotes
	For Each oPN As PunchNote In oPNs : oPN.DimensionStyle = oDStyles.PunchNoteStyle : Next
	oSheet.Update
End Sub