Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting dimensions

Status
Not open for further replies.

EUANS

Mechanical
Nov 8, 2002
17
In thread559-118542 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.

 
Replies continue below

Recommended for you

Euans,

The simplest way to do that is to switch the sheet format.
See TemplateSwitch from faq559-1429

[cheers]
 
So... You only want to increment/decrement dimensions that are not set to use document precision, right?

-handleman, CSWP (The new, easy test)
 
In my case I select a bunch of dimensions and press Alt+1 to set them to one decimal, Alt+2 for two decimals, Alt+3 for three decimals or Alt+0 for no decimals. Obviously I have macros associated with these keys. Is that what you are looking for.

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.

 
Give this one a try. Run it after you run the other macro you use. It will increment or decrement precision on all dimensions that are not set to the document precision.

Code:
Dim swApp As SldWorks.SldWorks
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)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor