Updating DimStyle issue, can't differentiate between holes and general dims?

Updating DimStyle issue, can't differentiate between holes and general dims?

Anonymous
Not applicable
533 Views
1 Reply
Message 1 of 2

Updating DimStyle issue, can't differentiate between holes and general dims?

Anonymous
Not applicable

I have written a rule to see if a flat pattern is present and update the dim styles accordingly. It is supposed to change the dim style to 2 decimal places for all general dimensions and 3 decimal places for diameters/holes. My issue is: If there is only a diameter dimension present it will update just fine, but if there is a diameter dimension and a linear dimension it will error out. It seems to me when there are other general dimensions present it changes the class of the diameter dimension, but this is only speculation. Does anyone have any ideas here? My code is below and I have included some images of the error and what happens when it works correctly.


Sub Main() 'set drawing document Dim oDrawDoc As DrawingDocument = ThisDoc.Document Dim oView As DrawingView Dim oSheet As Sheet 'suppress all views that are not flat patterns For Each oSheet In oDrawDoc.Sheets For Each oView In oSheet.DrawingViews If Not oView.IsFlatPatternView = True Then oView.Suppressed = True End If Next Next 'sheet FormatHoles FormatGeneralDims 'unsuppress all views For Each oSheet In oDrawDoc.Sheets For Each oView In oSheet.DrawingViews If oView.Suppressed = True Then oView.Suppressed = False End If Next Next 'sheet End Sub Function FormatHoles 'set drawing document Dim oDrawDoc As DrawingDocument = ThisDoc.Document 'set the style manager Dim oStylesMgr As DrawingStylesManager = oDrawDoc.StylesManager 'declare variables Dim oDiaDim As DiameterGeneralDimension Dim oHoleDimStyle As DimensionStyle Dim oHoleDims As DrawingDimensions Dim oView As DrawingView Dim oSheet As Sheet For Each oSheet In oDrawDoc.Sheets For Each oView In oSheet.DrawingViews If oView.IsFlatPatternView = True Then oHoleDimStyle = oStylesMgr.DimensionStyles.Item("Decimal (3pls)") oHoleDims = oSheet.DrawingDimensions For Each oDiaDim In oHoleDims oDiaDim.Style = oHoleDimStyle Next End If Next 'view Next 'sheet End Function Function FormatGeneralDims 'set drawing document Dim oDrawDoc As DrawingDocument = ThisDoc.Document 'set the style manager Dim oStylesMgr As DrawingStylesManager = oDrawDoc.StylesManager Dim oDim As GeneralDimension Dim oDimStyle As DimensionStyle Dim oDims As DrawingDimensions Dim oView As DrawingView Dim oSheet As Sheet For Each oSheet In oDrawDoc.Sheets For Each oView In oSheet.DrawingViews If oView.IsFlatPatternView = True Then oDims = oSheet.DrawingDimensions oDimStyle = oStylesMgr.DimensionStyles.Item("Decimal (ANSI)") oHoleDimStyle = oStylesMgr.DimensionStyles.Item("Decimal (3pls)") For Each oDim In oDims If oDim.Style Is oHoleDimStyle Then 'Do Nothing Else oDim.Style = oDimStyle End If Next End If Next 'view Next 'sheet End Function
0 Likes
Accepted solutions (1)
534 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Accepted solution

I ended up figuring it out myself. I went a slightly different direction with my code and was able to get it to work. Here is the code if anyone is interested:

 

'set drawing document
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument

'set the style manager
Dim oStylesMgr As DrawingStylesManager = oDrawDoc.StylesManager

'declare variables
Dim oDim As DrawingDimension
Dim oDims As DrawingDimensions
Dim oDim2 As GeneralDimension
Dim oDimStyle As DimensionStyle
Dim oHoleDimStyle As DimensionStyle
Dim oView As DrawingView
Dim oSheet As Sheet

'suppress all views that are not flat patterns
For Each oSheet In oDrawDoc.Sheets
	For Each oView In oSheet.DrawingViews
		If Not oView.IsFlatPatternView = True Then
			oView.Suppressed = True
		End If
	Next 'view
Next 'sheet 

'cycle through sheets
For Each oSheet In oDrawDoc.Sheets
	For Each oView In oSheet.DrawingViews
		If oView.IsFlatPatternView = True Then
			
			oDims = oSheet.DrawingDimensions
			oDimStyle = oStylesMgr.DimensionStyles.Item("Decimal (ANSI)")
			oHoleDimStyle = oStylesMgr.DimensionStyles.Item("Decimal (3pls)")
			
			For Each oDim in oDims
			
				If TypeOf oDim Is DiameterGeneralDimension Then
					oDim2 = oDim
					oDim2.Style = oHoleDimStyle
				Else
					oDim2 = oDim
					oDim2.Style = oDimStyle
				End If
				
			Next
			
		End If
	Next 'view
Next 'sheet 

'unsuppress all views
For Each oSheet In oDrawDoc.Sheets
	For Each oView In oSheet.DrawingViews
		If oView.Suppressed = True Then
			oView.Suppressed = False
		End If
	Next 'view
Next 'sheet