3 Replies Latest reply on Feb 4, 2016 6:07 AM by Tom Strohscher

    Read Sketch Dimension Macro

    Tom Strohscher

      I need some help getting a dimension's value.

       

      My macro will change dim1, read dim2, write dim1 and dim2 to a text file.  Then increment dim1 again.

       

      This is for a part model.  The sketch can stay open.

      I shouldn't need help with looping or writing to a file.  Unless someone already has it created.

       

      Sub main()

      Set swApp = _

      Application.SldWorks

      Set Part = swApp.ActiveDoc

      Dim myModelView As Object

      Set myModelView = Part.ActiveView

      myModelView.FrameState = swWindowState_e.swWindowMaximized

      Dim myAngle As Object

      Dim myLength As Object

       

      'select dimension and change value

      Set myDimension = Part.Parameter("D1@Sketch27")

      myDimension.SystemValue = 0.2094395102393

       

      'Get Length...

        • Re: Read Sketch Dimension Macro
          Tom Strohscher

          I didn't think this was such a hard question?

              'read dimension

              myLength = Get????("D3@Sketch27")

           

          Dim swApp As Object

          Dim Part As Object

          Dim boolstatus As Boolean

          Dim longstatus As Long, longwarnings As Long

          Sub main()

          Set swApp = _

          Application.SldWorks

          Set Part = swApp.ActiveDoc

          Dim myModelView As Object

          Set myModelView = Part.ActiveView

          myModelView.FrameState = swWindowState_e.swWindowMaximized

          Dim myAngle As Object

          Dim myLength As Object

          Dim PI As Double

          ' Set PI

          PI = 4 * Atn(1)

          Dim TextFile As Integer

          Dim FilePath As String

          'What is the file path and name for the new text file?

            FilePath = "C:\MyFile.csv"

          'Determine the next file number available for use by the FileOpen function

            TextFile = FreeFile

          'Open the text file

            Open FilePath For Output As TextFile

          Set myAngle = Part.Parameter("D1@Sketch27")

          X = 0.25

          For i = 1 To 148

              myAngle.SystemValue = X * PI / 180

              'read dimension

              myLength = Get????("D3@Sketch27")

              'Write some lines of text

              Print #TextFile, X & ", " & myLength

              X = X + 0.25

          Next i

          'Save & Close Text File

            Close TextFile

          End Sub