0 Replies Latest reply on May 2, 2016 3:30 PM by Mark Treadwell

    Pack and go call selecting too many documents

    Mark Treadwell

      I have a macro set up to export all the files we archive when we release a drawing revision - .PDF, .DXF and Pack and Go to .ZIP. Today I noticed it taking a very long time to run on a drawing that isn't particularly large (33 unique parts), and when it was finished I had a 1.6GB zip file which included the top level assembly, 2 levels above the one shown in the drawing. Checking the file references and viewing the Pack and Go dialog "by hand" didn't show me any of the rogue models. We have plenty of carelessly built models with external references that would create this situation, but this doesn't seem to be one of them based on what I see in the Pack and Go window.

       

      What would cause a Pack and Go through the API to come up with a different set of files than what I see when I generate it myself? There aren't any (documented) switches in the 'GetPackandGo' command so I'm not sure how this would be happening.

       

      Here's my code, in case someone can point out an obvious error there:

       

      Option Explicit

       

      Dim swApp As SldWorks.SldWorks

      Dim swDoc As SldWorks.ModelDoc2

      Dim swDocExt As SldWorks.ModelDocExtension

      Dim swPackAndGo As SldWorks.PackAndGo

      Dim swPageSetup As SldWorks.PageSetup

      Dim swDocPrinter As String

      Dim Errors As Long

      Dim Warnings As Long

      Dim Status As Boolean

      Dim Statuses As Variant

       

       

      Dim DestPath As String

      Dim FileTyp As Integer

      Dim DestFolder As String

      Dim FileName As String

      Dim CurrentRev As String

       

       

      ' SolidWorks constants

      Global Const swDocPART = 1

      Global Const swDocASSEMBLY = 2

      Global Const swDocDRAWING = 3

      Sub main()

      Set swApp = Application.SldWorks

      Set swDoc = swApp.ActiveDoc

      Set swDocExt = swDoc.Extension

      Set swPageSetup = swDoc.PageSetup

       

       

      DestPath = "H:\Drawings for Release\"

      If Dir(DestPath, vbDirectory) = "" Then MkDir (DestPath)

        If swDoc Is Nothing Then                                 ' Is doc loaded

          MsgBox ("No document open.")                           ' Need a doc loaded

          End

        Else                                                        ' Doc loaded?

          FileTyp = swDoc.GetType                                ' Get doc type

          If FileTyp = swDocASSEMBLY Or FileTyp = swDocPART Then    ' Model ?

              MsgBox ("Open file is not a drawing.")                ' Reject

              End

          ElseIf FileTyp = swDocDRAWING Then                        ' Drawing ?

              FileName = Left(swDoc.GetTitle, 4)

              If Left(FileName, 2) = "FX" Then FileName = Left(swDoc.GetTitle, 6)

              CurrentRev = swDoc.CustomInfo("Revision")

              FileName = FileName & "REV" & CurrentRev

         

              swDoc.SaveAs4 DestPath & FileName & ".pdf", 0, 1, Errors, Warnings        ' Create PDF

              swDoc.SaveAs4 DestPath & FileName & ".dxf", 0, 1, Errors, Warnings        ' Create DXF

              Set swPackAndGo = swDocExt.GetPackAndGo

              Status = swPackAndGo.SetSaveToName(True, DestPath & FileName & ".zip")    'Set ZIP save name

              If Len(Dir$(DestPath & FileName & ".zip")) > 0 Then Kill (DestPath & FileName & ".zip") 'Delete existing .zip so they aren't combined.

              Statuses = swDocExt.SavePackAndGo(swPackAndGo)                            'Create ZIP

             

              'If MsgBox("Print drawing?", vbYesNo, "Export Complete") = vbYes Then    'Print drawing

                  'swPageSetup.Orientation = 2 'Landscape

                  'swPageSetup.PrinterPaperSize = 17 '11x17 (for HP5200)

                  'swPageSetup.ScaleToFit = True

                  'swDoc.Printer = "\\ALPHA\HP 5200 PCL_CAD"

                  'swDoc.PrintDirect

                  'swDocExt.PrintOut2 0, 1, True, "HP 5200 PCL_CAD", ""

                  'swDocExt.PrintOut3 0, 1, True, "\\ALPHA\HP 5200 PCL_CAD", "", True  'All sheets, one copy, high quality

              'End If

          Else                                                      ' Else doc type

            MsgBox "Active file is not a SolidWorks document.", vbExclamation

          End If                                                    ' End doc type

        End If                                                      ' End doc load

      End Sub