I worked on your SWITCH-STYLE rule a while, and I think I may have a solution for maintaining your tolerances the way you have them, when changing its style. Here's the modified code.
Sub Main
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oExists As Boolean = False
Dim oUParams As UserParameters = oDDoc.Parameters.UserParameters
Dim oUParam As UserParameter
Dim oValues(1) As String
oValues(0) = "TEMPLATE - IDW [IN-MM]"
oValues(1) = "TEMPLATE - IDW [MM-IN]"
For Each oUParam In oUParams
If oUParam.Name = "DimStyle" Then
oUParam.ExpressionList.SetExpressionList(oValues)
oExists = True
End If
Next
If oExists = False Then
oUParam = oUParams.AddByValue("DimStyle", oValues(0), UnitsTypeEnum.kTextUnits)
oUParam.ExpressionList.SetExpressionList(oValues)
End If
oUParam.IsKey = True
iLogicVb.UpdateWhenDone = True
Dim oSheet As Sheet
For Each oSheet In oDDoc.Sheets
Dim oStylesMgr As DrawingStylesManager = oDDoc.StylesManager
Dim oDimStyle As DimensionStyle
If DimStyle = "TEMPLATE - IDW [IN-MM]" Then
oDimStyle = oStylesMgr.DimensionStyles.Item("TPL-DIMENSION [IN-MM]")
iProperties.Value("Custom", "STYLEDIM") = "IN [MM]"
Else
oDimStyle = oStylesMgr.DimensionStyles.Item("TPL-DIMENSION [MM-IN]")
iProperties.Value("Custom", "STYLEDIM") = "MM [IN]"
End If
Dim oDims As DrawingDimensions = oSheet.DrawingDimensions
For Each oDim As GeneralDimension In oDims
Call ChangeStyle(oDim,oDimStyle)
Next
'Change PartsList style
Dim oPartslist As PartsList = oSheet.PartsLists(1)
If DimStyle = "TEMPLATE - IDW [IN-MM]" Then
'If oSheet.PartsLists(1) IsNot Nothing Then
oPartslist.Style = oDDoc.StylesManager.PartsListStyles.Item("TPL-BOM-[lb-kg]")
Else
oPartslist.Style = oDDoc.StylesManager.PartsListStyles.Item("TPL-BOM-[kg-lb]")
End If
' 'change Hole And Thread Notes
' Dim oThreadNote As HoleThreadNote
' For Each oThreadNote In oSheet.DrawingNotes.HoleThreadNotes
' Call ChangeStyle(oThreadNote,oDimStyle)
' Next
Next
End Sub
Sub ChangeStyle(oObj As GeneralDimension,oStyle As DimensionStyle)
'capture existing tolerance data, before change
Dim oTolType As ToleranceTypeEnum = oObj.Tolerance.ToleranceType
Dim oTolPrecision As Integer = oObj.TolerancePrecision
Dim oUpper As Double
Dim oLower As Double
Dim oSymOffset As Double
Select Case oTolType
Case ToleranceTypeEnum.kDefaultTolerance
oObj.Style = oStyle
oObj.Tolerance.SetToDefault
Case ToleranceTypeEnum.kBasicTolerance
oObj.Style = oStyle
oObj.Tolerance.SetToBasic
Case ToleranceTypeEnum.kDeviationTolerance
oUpper = oObj.Tolerance.Upper
oLower = oObj.Tolerance.Lower
oObj.Style = oStyle
oObj.Tolerance.SetToDeviation(oUpper, oLower)
oObj.TolerancePrecision = oTolPrecision
Case ToleranceTypeEnum.kMaxTolerance
oObj.Style = oStyle
oObj.Tolerance.SetToMax
Case ToleranceTypeEnum.kMinTolerance
oObj.Style = oStyle
oObj.Tolerance.SetToMin
Case ToleranceTypeEnum.kSymmetricTolerance
oSymOffset = oObj.Tolerance.Value 'Not sure if this line will work
oObj.Style = oStyle
oObj.Tolerance.SetToSymmetric(oSymOffset) 'Not sure if oSymOffset will contain a valid value
oObj.TolerancePrecision = oTolPrecision
End Select
End Sub
I currently have the HoleThreadNotes section commented out, because I was hoping to use the same sub routine for both the GeneralDimensions and the HoleThreadNotes, since the routine is basically the same, but haven't figured out how to deal with the object type difference yet.
Wesley Crihfield

(Not an Autodesk Employee)