Ilogic to change dimension style without change tolerances

Ilogic to change dimension style without change tolerances

Anonymous
Not applicable
786 Views
3 Replies
Message 1 of 4

Ilogic to change dimension style without change tolerances

Anonymous
Not applicable

Hello.

 

I have a problem and I need help from you to solve it.

I have a macro that alternates in styles MM [IN] and IN [MM], so far ok, however, when some dimension has tolerance, these values are lost when switching between styles and the dimensions are in the standard mode, MM [IN ] or IN [MM] without tolerance.

Could you help me on this ask?

0 Likes
787 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Perhaps if you posted your code here, we could take a look at it, to see if we can fix it for you.

Does your Macro change the dimension Style of the dimension, or just manually re-format the text (or FormattedText) of the dimension, or both?  If you're switching between established styles, we would need to know how those styles are set-up, so we can try to duplicate your situation.  Or you could attach a sample drawing file, that has those styles saved locally in the document.  Make sure none of the files you attach here have any personal or proprietary information in them.  Including a few screen shots of the dimension showing the way you want it, and the way it is currently, without being fixed, would probably help too.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

Anonymous
Not applicable

Thank you very much WCrihfield for your help with my question. I attached my drawing on the forum.

Within this idw there is a rule "SELECT-STYLE-UNITS" that is executed when opening the document as new, and another rule "SWITCH-STYLE" that changes the dimension style of a completed Project, for example.

The switches is running, but whoever has dimensions with tolerances, these toleranches are missed.

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

0 Likes