Converting dimensions
Converting dimensions
(OP)
In thread559-118542: UNITS-Can I configure to only have selection of millimeters or inches Stoker proposed a macro to simply toggle between metric (2 decimal place) & imperial (3 decimal place) dimensions. This macro has helped me enormously but doesn't do everything I would like it to do.
We predominantly use metric dimensions and unless otherwise stated on the drawing use the number of decimal places to denote the tolerance of individual dimensions.
For metric drawings:- X.XXXmm = +/-0.05mm ; X.XXmm = +/-0.1mm ; X.Xmm = +/-0.25mm
For imperial drawings;- X.XXXX" = +/-0.002" ; X.XXX" = +/-0.004" ; X.XX" = +/-0.01"
Therefore a typical drawing will have dimensions with various numbers of decimal places.
Stoker's macro switches all dimensions globally at a document setting level. Is there a way to modify the macro so that not only do the dimensions toggle between metric and imperial but depending on the number of decimal places a dimension has the appropriate metric/imperial equivalent is displayed?
X.XXXmm toggles to X.XXXX" and back to X.XXXmm
X.XXmm toggles to X.XXX" and back to X.XXmm
X.Xmm toggles to X.XX" and back to X.Xmm
To do this a global switch to document dimension settings can no longer be used. Instead, each dimension needs to be changed on an individual basis. I have no experience with macros/API and ask if anyone can confirm that this can be done & if so point me in the right direction.
We predominantly use metric dimensions and unless otherwise stated on the drawing use the number of decimal places to denote the tolerance of individual dimensions.
For metric drawings:- X.XXXmm = +/-0.05mm ; X.XXmm = +/-0.1mm ; X.Xmm = +/-0.25mm
For imperial drawings;- X.XXXX" = +/-0.002" ; X.XXX" = +/-0.004" ; X.XX" = +/-0.01"
Therefore a typical drawing will have dimensions with various numbers of decimal places.
Stoker's macro switches all dimensions globally at a document setting level. Is there a way to modify the macro so that not only do the dimensions toggle between metric and imperial but depending on the number of decimal places a dimension has the appropriate metric/imperial equivalent is displayed?
X.XXXmm toggles to X.XXXX" and back to X.XXXmm
X.XXmm toggles to X.XXX" and back to X.XXmm
X.Xmm toggles to X.XX" and back to X.Xmm
To do this a global switch to document dimension settings can no longer be used. Instead, each dimension needs to be changed on an individual basis. I have no experience with macros/API and ask if anyone can confirm that this can be done & if so point me in the right direction.






RE: Converting dimensions
The simplest way to do that is to switch the sheet format.
See TemplateSwitch from FAQ559-1429: How To Change Or Manage Document Properties And Templates.
RE: Converting dimensions
-handleman, CSWP (The new, easy test)
RE: Converting dimensions
Another scenario would be for you to preselect a number of dimensions and press (as an example) Alt+d to bring up a window with radio buttons for 0, 1, 2 or 3 decimals which you can select.
RE: Converting dimensions
CODE
Dim swDoc As SldWorks.ModelDoc2
Dim swDwg As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swDispDim As SldWorks.DisplayDimension
Dim KillFlag As Integer
Dim sMsg As String
Sub IncDecPrecision()
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
If swDoc.GetType <> swDocDRAWING Then
MsgBox "This macro only works for drawing files."
Exit Sub
End If
sMsg = "Click ""Yes"" to increment, ""No"" to decrement, or ""Cancel"" to quit."
KillFlag = MsgBox(sMsg, vbYesNoCancel, "Dimension Precision +/-")
If KillFlag = vbCancel Then
Exit Sub
End If
Set swDwg = swDoc
Set swView = swDwg.GetFirstView
While Not (swView Is Nothing)
Set swDispDim = swView.GetFirstDisplayDimension5
While Not swDispDim Is Nothing
If Not (swPrecisionFollowsDocumentSetting = swDispDim.GetPrimaryPrecision2) Then
If vbYes = KillFlag Then
swDispDim.SetPrecision2 swDispDim.GetPrimaryPrecision2 + 1, -1, -1, -1
Else
swDispDim.SetPrecision2 swDispDim.GetPrimaryPrecision2 - 1, -1, -1, -1
End If
End If
Set swDispDim = swDispDim.GetNext5
Wend
Set swView = swView.GetNextView
Wend
End Sub
-handleman, CSWP (The new, easy test)