4 Replies Latest reply on Oct 10, 2014 6:16 AM by Joy Garon

    Print task: Only print sheets beginning with special word

    Lars Uhlenhaut

      Hi together,

      is there a possibility to automatically print sheets only beginning with a special word (e.g. 'Print')?

      I found an entry in the task script, but I cannot find an corresponding entry on the GUI of the print task. In the convert task I can choose the sheet.

      Here is the part of the script.

       

      [...]

          Set swExtension = swModel.Extension
         
          Dim vPrintSheets As Variant

          'If sheet is specified, find out its page number and add it to the array of sheets to be printed.
          If Len(docCfgOrSheet) > 0 And docType = swDocDRAWING Then
              Dim vSheetNames As Variant
              Dim nPrintSheets(0) As Long
              Dim swDraw As SldWorks.DrawingDoc
              Dim swSheet As SldWorks.Sheet
              Set swDraw = swModel
              vSheetNames = swDraw.GetSheetNames
              For i = 0 To UBound(vSheetNames)
                  If LCase(vSheetNames(i)) = LCase(docCfgOrSheet) Then
                      nPrintSheets(0) = i + 1
                      vPrintSheets = nPrintSheets
                      Exit For
                  End If

      [...]

       

      The variable 'docCfgOrSheet' seems to be a system variable. Where is it set in the GUI? Can I set it manually in the skript? e.g. docCfgOrSheet = "Print*"

       

      Lars

        • Re: Print task: Only print sheets beginning with special word
          Jeff Sweeney

          Interesting it isn't in the GUI since it is in the convert task.

           

          You may edit the code in the "advanced scripting options"

          • Re: Print task: Only print sheets beginning with special word
            Joy Garon

            Hi Lars,

             

            It is possible to modify using Advanced Scripting Options on the Files step of the Print task.

             

            adv_script_options.jpg

             

            Make the changes detailed below to the task advanced script.  This modification will apply for any file type to only process a configuration or sheet starting with a certain string. 

             

            EXISTING DEFAULT CODE SECTION:

             

            Sub main()

               

                On Error GoTo Fail:

             

                Dim docFileName As String

                Dim docCfgOrSheet As String

                Dim sNumCopies As String

               

                docFileName = "<Filepath>"

                docCfgOrSheet = "<SelCfgOrSheet>"

                sNumCopies = "[__printer_copycount]"

             

             

                Dim iNumCopies As Integer

                iNumCopies = 1

                If (Len(sNumCopies) > 0) Then

                    iNumCopies = CInt(sNumCopies)

                End If

             

            CHANGE TO:

             

            Sub main()

               

                On Error GoTo Fail:

             

                Dim docFileName As String

                Dim docCfgOrSheet As String

                Dim sNumCopies As String

                Dim docSheetPrefix As String

               

                docFileName = "<Filepath>"

                docCfgOrSheet = "<SelCfgOrSheet>"

                sNumCopies = "[__printer_copycount]"

             

               ' only process sheets that start with PRNT

                docSheetPrefix = Left(docCfgOrSheet, 4)

             

                If docSheetPrefix <> "PRNT" Then

                   Exit Sub

                End If

               

                Dim iNumCopies As Integer

                iNumCopies = 1

                If (Len(sNumCopies) > 0) Then

                    iNumCopies = CInt(sNumCopies)

                End If

             

            The configuration or sheet name is passed to the script in the <SelCfgOrSheet> parameter. 

            The script is modified to add a new variable docSheetPrefix which (in this example) is then set to the left 4 characters of the <SelCfgOrSheet> parameter.

            This variable is checked for a certain value (PRNT in this example) and the script exited if the value does not match.

             

            Note that to avoid any user confusion the 'Show print dialog box' option should be disabled.

            adv_script_options2.jpg

             

            As with any modifications to scripts, please make sure that you understand and test the changes thoroughly in your environment to make sure it meets your needs.

             

            Regards,

            Joy