6 Replies Latest reply on Oct 24, 2012 11:23 AM by Chris Sparber

    Extracting data from a drawing

    Chris Sparber

      Hello All--

       

      I have my drawing template set to use configuration specific properties from a selected view to populate the drawing name and drawing number.  Then revision is a user input and the created date is a sw custom property.  Is there a way to pull that data out of the active sheet document fields and put it onto an excel sheet?  Thanks!!

       

      Sincerely,

       

      Chris

        • Re: Extracting data from a drawing
          Michael Jeffries

             Yes there is!  Just keep in mind you need to change the .CustomInfo("") to your custom parameter name, the attached code should do exactly what you want!  You need to go to References and add the Microsoft Excel Object Type Library for the excel functionality to work.

           

          Dim swApp As SldWorks.SldWorks

              Dim swModel As ModelDoc2

              Dim PartNum, DateCreated As String

           

              Dim xlApp As Excel.Application

              Dim xlBook As Excel.Workbook

              Dim xlSheet As Excel.Worksheet

           

              Sub Main()

                  Set swApp = New SldWorks.SldWorks

                  Set swModel = swApp.ActiveDoc

                  Debug.Print("******** Time Stamp: " & Date.Today & " ************")

                  PartNum = swModel.CustomInfo("Enter your Custom parameter Here")

                  DateCreated = swModel.SummaryInfo(swSummInfoField_e.swSumInfoCreateDate)

                  Debug.Print("Part Number: " & PartNum)

                  Debug.Print("Date Created: " & DateCreated)

                  ExcelStuff()

           

              End Sub

           

              Sub ExcelStuff()

                 Set  xlApp = CreateObject("Excel.Application")

                 Set xlBook = xlApp.Workbooks.Add()

                 Set xlSheet = xlBook.Worksheets(1)  'First worksheet in workbook

           

                  With xlSheet

                      .Cells(1, 1).value = "Instance"

                      .Cells(1, 2).value = "Part Number"

                      .Cells(1, 3).value = "Date Created"

                      For i = 2 To 11

                          .Cells(i, 1).value = i

                      Next

           

                      .Cells(2, 2).value = PartNum

                      .Cells(2, 3).value = DateCreated

                  End With

                  xlApp.Visible = True

              End Sub

          End Class

          • Re: Extracting data from a drawing
            Chris Sparber

            Mike the variable comes from the part configuration specific properties.  When I set up my drawing template I set the drawing title and part number to populate based on the part properties in a selected view. 

             

            Thanks Deepak for the two examples.

            I understand how to assign note identities to fields in the title block (done automatically); however, I am not sure how to assign a name to an annotation that you put on your drawing.  How do you assign a name to an annotation on the drawing sheet?  Thanks.

             

            Sincerely,

             

            Chris

              • Re: Extracting data from a drawing
                Chris Sparber

                I found that using notes within a titleblock is highly efficient.  I can also use configuration specific properties from parts in specific views on the sheet to automatically populate the values.  This takes me out the business of manually creating excel spreadsheets to manage the drawings for specific projects.  Thanks.

                 

                Sincerely,

                 

                Chris