3 Replies Latest reply on Mar 6, 2018 12:28 PM by Josh Brady

    Export Inspection Dimensions Macro

    Ryan Priddy

      Hello Everyone!

      I am in search of a macro that only exports out to excel dimensions + tolerances that are marked for inspection (ie the ones with the circle/pill capsule around them). I know Solidworks Makes an Inspection Tool/add-in that does this, but I only need this one feature.

       

      I have found some macros on here, but they export out all of the dimensions including the one pertaining to the sheet.

       

      Any help would be great!

      Ryan

        • Re: Export Inspection Dimensions Macro
          Josh Brady

          Recommend getting your feet wet editing code.

           

          Find one that does as close as possible to what you want.  Somewhere in that code will be something like:

           

          set swDispDim=(something or other)

           

          This is the display dimension object.  You can test this object to see if it is marked for inspection with .Inspection.

          So, somewhere after that line you would put:

           

          If swDispDim.Inspection Then

               [put all the code that does the exporting inside this "If" block.]

               [put the "End If" right before it grabs the next dimension.  Probably with something like "swDispDim.GetNext"]

          End if

            • Re: Export Inspection Dimensions Macro
              Ryan Priddy

              Great! I was able to modify some existing code that I found on the forums to get it to do what I wanted it to. My next question is how do I get it to cycle through all of the Sheets rather than the active sheet?

               

              I also would like to pull the part name (6 digit number), description and Revision that are stored in the custom properties.

               

              Here is my code that I modified... I got it from a search on the forums

               

              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 swDim As SldWorks.Dimension

              Dim swTol As SldWorks.DimensionTolerance

              Dim xlApp As Excel.Application

              Dim xlSheet As Excel.Worksheet

              Dim xlBooks As Excel.Workbooks

              Dim CurRow As Long

              Const STARTROW As Long = 1

              Const PARTNAME As Long = 1

              Const DIMNAMECOL As Long = 2

              Const INSPECTION As Long = 3

              Const DIMVALCOL As Long = 4

              Const DIMTOLTYPECOL As Long = 5

              Const DIMUPPERTOLVALCOL As Long = 6

              Const DIMLOWERTOLVALCOL As Long = 7

              Const DIMTOLFITCLASSCOL As Long = 8

              Const TOLSCALEFACTOR As Double = 1000

               

               

              Sub ExportDims()

               

               

              Dim NumTolVals As Integer

              Dim TolIsFit As Boolean

               

               

              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

               

               

              Set swDwg = swDoc

              Set xlApp = CreateObject("Excel.Application")

              xlApp.Visible = True

              Set xlBooks = xlApp.Workbooks

              xlBooks.Add

              Set xlSheet = xlApp.ActiveSheet

              CurRow = STARTROW

              xlSheet.Cells(CurRow, PARTNAME).Value = "Part Name"

              xlSheet.Cells(CurRow, DIMNAMECOL).Value = "Dimension Name"

              xlSheet.Cells(CurRow, INSPECTION).Value = "Inspection Dimension"

              xlSheet.Cells(CurRow, DIMVALCOL).Value = "Nominal Value"

              xlSheet.Cells(CurRow, DIMTOLTYPECOL).Value = "Tolerance Type"

              xlSheet.Cells(CurRow, DIMUPPERTOLVALCOL).Value = "Upper Tol"

              xlSheet.Cells(CurRow, DIMLOWERTOLVALCOL).Value = "Lower Tol"

              CurRow = CurRow + 1

               

               

              Set swView = swDwg.GetFirstView

              While Not (swView Is Nothing)

                  Set swDispDim = swView.GetFirstDisplayDimension5

                  While Not swDispDim Is Nothing

                      Set swDim = swDispDim.GetDimension

                      Set swTol = swDim.Tolerance

                      If swDispDim.INSPECTION Then

                      xlSheet.Cells(CurRow - 6, INSPECTION).Value = swDispDim.INSPECTION

                      xlSheet.Cells(CurRow - 6, DIMNAMECOL).Value = swDim.FullName

                      xlSheet.Cells(CurRow - 6, DIMVALCOL).Value = swDim.Value

                      xlSheet.Cells(CurRow - 6, DIMTOLTYPECOL).Value = GetTolTypeName(swTol, NumTolVals, TolIsFit)

                      If NumTolVals > 0 Then

                          xlSheet.Cells(CurRow - 6, DIMUPPERTOLVALCOL).Value = swTol.GetMaxValue * TOLSCALEFACTOR

                      End If

                      If NumTolVals > 1 Then

                          xlSheet.Cells(CurRow - 6, DIMLOWERTOLVALCOL).Value = swTol.GetMinValue * TOLSCALEFACTOR

                      End If

                      End If

                      Set swDispDim = swDispDim.GetNext5

                      CurRow = CurRow + 1

                  Wend

                  Set swView = swView.GetNextView

              Wend

               

               

              xlApp.Range("A:Z").EntireColumn.AutoFit

              End Sub

               

               

               

               

              Function GetTolTypeName(ByRef myTol As SldWorks.DimensionTolerance, ByRef NumVals As Integer, ByRef FitTol As Boolean) As String

              Dim s As String

              FitTol = False

              Select Case myTol.Type

                  Case swTolNONE

                      s = "None"

                      NumVals = 0

                  Case swTolInspection

                      s = "Inspection"

                      NumVals = 2

                  Case swTolBASIC

                      s = "Basic"

                      NumVals = 0

                  Case swTolBILAT

                      s = "Bilateral"

                      NumVals = 2

                  Case swTolLIMIT

                      s = "Limit"

                      NumVals = 2

                  Case swTolSYMMETRIC

                      s = "Symmetric"

                      NumVals = 1

                  Case swTolMIN

                      s = "Minimum"

                      NumVals = 0

                  Case swTolMAX

                      s = "Maximum"

                      NumVals = 0

                  Case swTolMETRIC

                      s = "Metric"

                      NumVals = 2

                  Case swTolFIT

                      s = "Fit"

                      NumVals = 0

                      FitTol = True

                  Case swTolFITWITHTOL

                      s = "Fit With Tolerance"

                      NumVals = 2

                      FitTol = True

                  Case swTolFITTOLONLY

                      s = "Fit, Tolerance Only"

                      NumVals = 2

                      FitTol = False

                  Case swTolBLOCK

                      s = "Block"

                      NumVals = 2

                      FitTol = False

              End Select

              GetTolTypeName = s

              End Function

               

              Thanks!

              Ryan

                • Re: Export Inspection Dimensions Macro
                  Josh Brady

                  Ryan Priddy wrote:

                   

                  Great! I was able to modify some existing code that I found on the forums to get it to do what I wanted it to. My next question is how do I get it to cycle through all of the Sheets rather than the active sheet?

                   

                  I also would like to pull the part name (6 digit number), description and Revision that are stored in the custom properties.

                   

                   

                   

                  You can read properties using the CustomPropertyManager interface.

                   

                  To cycle through the sheets, I would recommend getting an array of the sheet names using GetSheetNames, then looping through that array, activating each sheet by name with ActivateSheet.  This new loop would enclose the block of existing the code starting with Set SwView = swDwg.GetFirstView and ending with Wend