Check if drawing has a Dimension Style Active.

Check if drawing has a Dimension Style Active.

C_Haines_ENG
Collaborator Collaborator
252 Views
2 Replies
Message 1 of 3

Check if drawing has a Dimension Style Active.

C_Haines_ENG
Collaborator
Collaborator

I am trying to check if any dimensions in my drawing are still in metric.

 

We do all of our standard drawings in metric, but sometimes we need to switch them to impertial to share.

 

	For Each oBDimSet As BaselineDimensionSet In oSheet.DrawingDimensions.BaselineDimensionSets
		If oBDimSet.Style = oDSMgr.DimensionStyles.Item("mm"
			UnitErrorCount = UnitErrorCount + 1
		End If	

 I have a snippet of the kind of code im using, however it returns the error  "Operator '=' is not defined for type DimensionStyle.

 

Does anyone know of a way to do this?

0 Likes
Accepted solutions (1)
253 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

It wants you to compare them using 'Is' instead of '=', because they are objects, not data.

For Each oBDimSet As BaselineDimensionSet In oSheet.DrawingDimensions.BaselineDimensionSets
		If oBDimSet.Style Is oDSMgr.DimensionStyles.Item("mm")
			UnitErrorCount = UnitErrorCount + 1
		End If

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @C_Haines_ENG.  Here is an example iLogic rule I just created that may help.  This one is designed to check every dimension on every sheet to see if it is using your metric DimensionStyle, and if it is, change its Style to your imperial DimensionStyle.  So, it first tries to get both of those DimensionStyles to variables before it begins looping through all dimensions.  If it does not find either one, it will let you know, then exit the rule without continuing.  If it finds both, it then continues to check and change the style of all dimensions.  The process is reversible too, because I made it into a separate Sub routine which you can supply the two styles to, so you can just reverse them.

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 oDimStyles As DimensionStylesEnumerator = oDDoc.StylesManager.DimensionStyles
	
	'try to get your regular metric DimensionStyle
	Dim oMMDimStyle As DimensionStyle = Nothing
	Try
		oMMDimStyle = oDimStyles.Item("mm")
	Catch
		MsgBox("Error trying to get DimensionStyle named 'mm'.", vbCritical, "")
		Exit Sub
	End Try
	If IsNothing(oMMDimStyle) Then Exit Sub
		
	'try to get your Imperial DimensionStyle
	Dim oInDimStyle As DimensionStyle = Nothing 'for Imperial Style
	Try 'assuming your Imperial style is named "in" for inches
		oInDimStyle = oDimStyles.Item("in") '<<<EDIT THIS>>>
	Catch
		MsgBox("Error trying to get DimensionStyle named 'in'.", vbCritical, "")
		Exit Sub
	End Try
	If IsNothing(oInDimStyle) Then Exit Sub
	ChangeAllDimStyles(oDDoc, oMMDimStyle, oInDimStyle)
End Sub

Sub ChangeAllDimStyles(oDrawDoc As DrawingDocument, oFrom As DimensionStyle, oTo As DimensionStyle)
	'loop through all dimensions and change their Style
	For Each oSheet As Sheet In oDrawDoc.Sheets
		Dim oDDims As DrawingDimensions = oSheet.DrawingDimensions
		Dim oBLDimSets As BaselineDimensionSets = oDDims.BaselineDimensionSets
		Dim oCDimSets As ChainDimensionSets = oDDims.ChainDimensionSets
		Dim oGenDims As GeneralDimensions = oDDims.GeneralDimensions
		Dim oODims As OrdinateDimensions = oDDims.OrdinateDimensions
		Dim oODimSets As OrdinateDimensionSets = oDDims.OrdinateDimensionSets
		If oBLDimSets.Count > 0 Then
			For Each oBLDimSet As BaselineDimensionSet In oBLDimSets
				If oBLDimSet.Style Is oFrom Then
					oBLDimSet.Style = oTo
				End If
			Next
		End If
		If oCDimSets.Count > 0 Then
			For Each oCDimSet As ChainDimensionSet In oCDimSets
				If oCDimSet.Style Is oFrom Then
					oCDimSet.Style = oTo
				End If
			Next
		End If
		If oGenDims.Count > 0 Then
			For Each oGenDim As GeneralDimension In oGenDims
				If oGenDim.Style Is oFrom Then
					oGenDim.Style = oTo
				End If
			Next
		End If
		If oODims.Count > 0 Then
			For Each oODim As OrdinateDimension In oODims
				If oODim.Style Is oFrom Then
					oODim.Style = oTo
				End If
			Next
		End If
		If oODimSets.Count > 0 Then
			For Each oODimSet As OrdinateDimensionSet In oODimSets
				If oODimSet.Style Is oFrom Then
					oODimSet.Style = oTo
				End If
			Next
		End If
	Next
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes