5 Replies Latest reply on Jun 18, 2014 7:53 AM by Joshua Zastrow

    Exporting Drawing Dimensions to Excel VBA

    Joshua Zastrow

      Hi All,


      I am trying to automate a manual process where I take all the dimensions outlined in a drawing and put them in a column in Excel. These dimensions are also called out in my 3D model.


      I would like to automate this somewhat, and have a solid understanding of VBA for Excel but haven't ever worked for it with Solidworks. Does anyone know what the object hierarchy is for dimensions, how to call on them, or useful functions/sample code for this project?



        • Re: Exporting Drawing Dimensions to Excel VBA
          Christopher Estelow

          Have a look at the post here to see if it has what your looking for.



          • Re: Exporting Drawing Dimensions to Excel VBA
            Klaudiusz Skiba

            Explain exactly what you want macro to do.

            You only mentioned taking dimensions from drawing and putting them in excel.

            Anything else?

            Because that is really simple and I can help you with that.

              • Re: Exporting Drawing Dimensions to Excel VBA
                Joshua Zastrow

                Just that. So:


                Manually, I create a 3D model and dimension it with tolerances. I then create a drawing and dimension it accordingly.


                Macro: For each drawing sheet I make, for each dimension, copy dimension (including tolerances-I use limit tolerances), open (specific) excel spreadsheet, paste in column B, row i. repeat for each dimension in the sheet. Ideally it would also recognize geometric tolerances and be able to copy those and paste into Excel.


                additional features would be recognizing a string in the drawing table box (i.e drawing number, operation number). I don't know how to locate those variables with a Solidworks Macro, but can work with them once I have the variable in Excel.



              • Re: Exporting Drawing Dimensions to Excel VBA
                Artem Taturevych

                Here is the simple macro to traverse dimension in drawing and output the values. If you know Excel API it would be easy for you to change the macro to suit your needs:


                Dim swApp As SldWorks.SldWorks

                Dim swDraw As SldWorks.DrawingDoc

                Dim swView As SldWorks.View


                Sub main()


                    Set swApp = Application.SldWorks

                    Set swDraw = swApp.ActiveDoc


                    Set swView = swDraw.GetFirstView


                    Do While Not swView Is Nothing


                        Dim vDims As Variant

                        Dim swDispDim As SldWorks.DisplayDimension

                        Dim swDim As SldWorks.Dimension


                        Dim i As Integer

                        vDims = swView.GetDisplayDimensions


                        If Not IsEmpty(vDims) Then


                            For i = 0 To UBound(vDims)


                                Set swDispDim = vDims(i)


                                Set swDim = swDispDim.GetDimension


                                Debug.Print "Dimension to export to Excel: " & swDim.FullName & " = " & swDim.GetSystemValue2("") & " meters"


                            Next i


                        End If


                        Set swView = swView.GetNextView




                End Sub

                • Re: Exporting Drawing Dimensions to Excel VBA
                  Joshua Zastrow

                  Thanks everyone for your help, much appreciated. Kudos to Josh Brady for writing such a robust program; I think I will be able to easily tweak it for my application.