Use Document's Units Code

Discussion in 'SolidWorks' started by inthepickle, Nov 9, 2005.

  1. inthepickle

    inthepickle Guest

    I have a part fully defined and modeled in SolidWorks Office 2005. The
    Document Properties -> Units is set for a 3 place decimal. There are 3
    reference dimensions that have been put on the part manually.

    RD1@Annotations
    RD2@Annotations
    RD3@Annotations

    I am trying to write a macro that will select these dimension, go into
    more properties, and then say "do not use document units", and set it
    to fraction rounded to the 16th.

    I tried to use SolidWorks and record the macro myself, but it will not
    record correctly. It only records the code used to select these
    dimension. It will not show how to only change these dimensions to a
    fraction.

    I have went through SolidWorks API helo, and came up empty handed. I
    am sure this something really simple, but I can't find it. Could
    someone please give me the lines of code that will change these
    dimensions that way I need them, or at least point me in the right
    direction.

    Thanks
     
    inthepickle, Nov 9, 2005
    #1
  2. inthepickle

    Tin Man Guest

    The below macro will change all the *preselected* dimensions to 1/16th
    fractional.

    Ken



    '******************************************************************************
    ' Fractional.swb
    '******************************************************************************
    Dim swApp As Object
    Dim swModel As Object
    Dim swSelMgr As Object
    Dim selCount As Integer
    Dim selType As Integer
    Dim retval As Variant
    Dim CurrentSelDimension As Object
    Dim boolstatus As Boolean
    Dim useDoc, roundToFraction As String
    Dim uType, fractBase, fractDenom As Long
    Dim i As Integer

    Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc

    If swModel.GetUserPreferenceIntegerValue(swUnitsLinear) <> swINCHES
    Then
    boolstatus = MsgBox("Program only works for files with INCH
    Primary" & Chr(13) & _
    "Units in the Doument Settings." & Chr(13) & _
    "Ending routine.", vbExclamation)
    End
    End If

    useDoc = False 'TRUE=Use the document settings for units
    uType = swINCHES 'Set to Inches
    fractBase = swFRACTION 'Set to Fractions
    fractDenom = 16 'Denominator Base unit
    roundToFraction = True 'TRUE rounds values to the nearest fraction,
    FALSE displays fractions only if the values are exact

    Set swSelMgr = swModel.SelectionManager()
    selCount = swSelMgr.GetSelectedObjectCount()

    If (selCount > 0) Then
    For i = 1 To selCount
    selType = swSelMgr.GetSelectedObjectType2(i)
    If (selType = swSelDIMENSIONS) Then
    Set CurrentSelDimension = swSelMgr.GetSelectedObject3(i)
    CurrentSelDimension.SetDual True
    CurrentSelDimension.SetUnits useDoc, uType, fractBase,
    fractDenom, roundToFraction
    End If
    Next
    End If

    swModel.ClearSelection2 True
    swModel.GraphicsRedraw2
    End Sub
     
    Tin Man, Nov 9, 2005
    #2
  3. inthepickle

    inthepickle Guest

    thanks ken - the code you gave me worked like a charm
     
    inthepickle, Nov 9, 2005
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.