18 Replies Latest reply on Nov 15, 2012 8:36 AM by David Brissenden

    Printing Issue

    David Brissenden

      Hi,

       

      I'm trying to print a document out to a specific printer and SW 2006 is having none of it. 

       

      I've followed the example here: http://help.solidworks.com/2011/English/api/sldworksapi/Print_Drawing_as_High_Quality_Example_VB.htm with my own printer but it is adamant it wants to always print to one specific printer and not the one I choose.

       

      The code I have is:

       

      Private Sub cmdPrintDrawings_Click()

          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Dim swModelExt As SldWorks.ModelDocExtension

          Dim swPageSetup As SldWorks.PageSetup

          Dim lSheets(0) As Long

         

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

         

          Set swPageSetup = swModel.PageSetup

          swPageSetup.Orientation = 2

         

          lSheets(0) = 0

         

          Set swModelExt = swModel.Extension

          swModelExt.PrintOut2 lSheets, 1, False, "\\Test\Test Plotter", ""

       

      End Sub

       

      What am I doing wrong?

       

      Thanks

        • Re: Printing Issue
          Artem Taturevych

          Try to set the printer via ModelDoc2::Printer  and use ModelDoc2::PrintDirect  for printing.

          ______________________

          Regards,

          Artem Taturevych

          Application Engineer at Intercad

          http://intercad.com.au/

          Tel: +61 2 9454 4444

          • Re: Printing Issue
            David Brissenden

            Ok , all seems solved after a reboot.....something somewhere seems to have got confused (more than me!!)

             

            The next question is how do you set the papersize?  There is a PrinterPaperSize property under the PageSetup but I am finding conflicting info regarding setting the papersize.  Some information is saying A3=8 A4=9 whilst others are saying different A2=8 A1=9.

             

            Obviously different printers have different paper sizes available to print on, but how do you find our the correct constant?

             

            Thanks for your help guys.

              • Re: Printing Issue
                Deepak Gupta

                You may define the paper size using PrinterPaperWidth and PrinterPaperLength

                  • Re: Printing Issue
                    David Brissenden

                    I thought this was possible however

                     

                        Set swPageSetup = swModel.PageSetup

                        swPageSetup.Orientation = 2

                        swPageSetup.ScaleToFit = True

                        swPageSetup.PrinterPaperLength = 2970

                        swPageSetup.PrinterPaperWidth = 4200

                     

                     

                    this is what I set and it doesn't print A3 as it is supposed to.  I've tried swapping the length and width around but there is no difference.  The printer supports A3.....so I can't see why this doesn't work

                    • Re: Printing Issue
                      David Brissenden

                      If I set:

                       

                          Set swPageSetup = swModel.PageSetup

                          swPageSetup.Orientation = 2

                          swPageSetup.ScaleToFit = True

                          swPageSetup.PrinterPaperLength = 297

                          swPageSetup.PrinterPaperWidth = 420

                       

                      The printer seems to think it is JISB4 size. 

                       

                      I'm guessing this is an issue with scaling but still doesn't alter the fact that it doesn't print A3 / A4 as it should.

                       

                      Cannot believe there are so many issues with this software....

                        • Re: Printing Issue
                          Michael Jeffries

                          I don't believe it's so much solidworks as it's fairly unfriendly to access printer specs (for the selected printer) in VBA.  I can easily tell you what paper sizes are available to print on using VB.NET, but when it comes to VBA I am at a loss..  I have two different network printers that (as you pointed out) have different paper sizes listed (from excel or any other application print dialog):

                           

                          RicohCOL

                           

                          PaperSize / PaperName

                          0       12" x 18"

                          17       11" x 17"

                          5       Legal (8.5" x 14")

                          1       Letter (8.5" x 11")

                          7       Executive (7.25" x 10.5")

                          6       5.5" x 8.5"

                          8       A3 (297 x 420 mm)

                          9       A4 (210 x 297 mm)

                          11       A5 (148 x 210 mm)

                          70       A6 (105 x 148 mm)

                          12       B4 JIS (257 x 364 mm)

                          13       B5 JIS (182 x 257 mm)

                          88       B6 JIS (128 x 182 mm)

                          0       8" x 13"

                          0       8.25" x 13"

                          14       8.5" x 13"

                          20       Com10 Env. (4.125" x 9.5")

                          37       Monarch Env. (3.875" x 7.5")

                          27       DL Env. (110 x 220 mm)

                          31       C6 Env. (114 x 162 mm)

                          28       C5 Env. (162 x 229 mm)

                          0       Custom Paper Size

                           

                          RicohENG

                           

                           

                          PaperSize / PaperName

                          0       12" x 18"

                          17       11" x 17"

                          5       Legal (8.5" x 14")

                          1       Letter (8.5" x 11")

                          7       Executive (7.25" x 10.5")

                          6       5.5" x 8.5"

                          8       A3 (297 x 420 mm)

                          9       A4 (210 x 297 mm)

                          11       A5 (148 x 210 mm)

                          70       A6 (105 x 148 mm)

                          12       B4 JIS (257 x 364 mm)

                          13       B5 JIS (182 x 257 mm)

                          88       B6 JIS (128 x 182 mm)

                          0       8" x 13"

                          0       8.25" x 13"

                          14       8.5" x 13"

                          0       Custom Paper Size

                           

                           

                          Where Modeldoc2.pagesetup.printerpapersize = PaperSize (from above tables)

                          These are not in any relation to swDwgPaperSizes_e (enumeration).

                           

                          You can use the following to print, but I was unable to 1) check selected printer paper sizes and 2) find the callout for A0, A1, A2, etc...

                           

                           

                          '***************************************************************************************************************

                              Dim swApp As SldWorks.SldWorks

                              Dim swModel As ModelDoc2

                              Dim swDraw As DrawingDoc

                              Dim swPart As PartDoc

                              Dim swAsm As AssemblyDoc

                           

                              Dim swSheet As Sheet

                              Dim sheetsize As String     'Sheet Size Variable (retreived from SW)

                              Dim paperSize As swDwgPaperSizes_e

                              Dim width As Double

                              Dim height As Double

                           

                              Sub swPrint()

                                  Select Case swApp Is Nothing

                                      Case True

                                          Set swApp = New SldWorks.SldWorks

                                  End Select

                                  Set swModel = swApp.ActiveDoc

                           

                                  Select Case swModel.GetType

                                      Case swDocumentTypes_e.swDocDRAWING

                                          Set swDraw = swModel

                                      Case Else

                                          swApp.SendMsgToUser ("Please open a drawing document and try again!")

                                          Exit Sub

                                          'Nothing

                                  End Select

                                  swPrintSettings("RicohCOL")     'Prints to the Specified Printer Name, you can get your printer names by going to Windows Button >>> Devices and printers

                           

                              End Sub

                           

                              Sub swPrintSettings(ByVal PrinterName As String)

                                  Dim swPageSetup As PageSetup

                           

                                  Set swPageSetup = swModel.PageSetup

                                  swPageSetup.ScaleToFit = True

                           

                                  swModel.Printer = PrinterName

                                  Select Case Get_SheetSize()

                                      Case "A"

                                          swModel.PageSetup.PrinterPaperSize = 1

                                      Case "AV"

                                          swModel.PageSetup.PrinterPaperSize = 1

                                      Case "B"

                                          swModel.PageSetup.PrinterPaperSize = 17

                                      Case "C"

                                          swModel.PageSetup.PrinterPaperSize = 17

                                      Case "D"

                                          swModel.PageSetup.PrinterPaperSize = 17

                                      Case "E"

                                          swModel.PageSetup.PrinterPaperSize = 17

                                      Case "A0"

                                          swModel.PageSetup.PrinterPaperSize = 1

                                      Case "A1"

                                          swModel.PageSetup.PrinterPaperSize = 1

                                      Case "A2"

                                          swModel.PageSetup.PrinterPaperSize = 1

                                      Case "A3"

                                          swModel.PageSetup.PrinterPaperSize = 8

                                      Case "A4"

                                          swModel.PageSetup.PrinterPaperSize = 9

                                      Case "A4v"

                                          swModel.PageSetup.PrinterPaperSize = 9

                                      Case "UserDefined"

                           

                                  End Select

                           

                                  Select Case swModel.GetType

                                      Case swDocumentTypes_e.swDocDRAWING

                                         swModel.PrintOut 1, swDraw.GetSheetCount, 1, False, swModel.Printer, swPageSetup.ScaleToFit, False

                           

                                      Case Else

                                          MsgBox ("Open a drawing and try again")

                                          Exit Sub

                                  End Select

                              End Sub

                           

                              Function Get_SheetSize() As String

                                  Set swSheet = swDraw.GetCurrentSheet

                           

                                  If Not swSheet Is Nothing Then

                                      Set swSheet = swDraw.GetCurrentSheet

                                      paperSize = swSheet.GetSize(width, height)

                                      Debug.Print ("swDwgPaperSize = " & paperSize)

                           

                                      Select Case paperSize

                                          Case swDwgPaperSizes_e.swDwgPaperAsize

                                              sheetsize = "A"

                                          Case swDwgPaperSizes_e.swDwgPaperAsizeVertical

                                              sheetsize = "AV"

                                          Case swDwgPaperSizes_e.swDwgPaperBsize

                                              sheetsize = "B"

                                          Case swDwgPaperSizes_e.swDwgPaperCsize

                                              sheetsize = "C"

                                          Case swDwgPaperSizes_e.swDwgPaperDsize

                                              sheetsize = "D"

                                          Case swDwgPaperSizes_e.swDwgPaperEsize

                                              sheetsize = "E"

                                          Case swDwgPaperSizes_e.swDwgPaperA0size

                                              sheetsize = "A0"

                                          Case swDwgPaperSizes_e.swDwgPaperA1size

                                              sheetsize = "A1"

                                          Case swDwgPaperSizes_e.swDwgPaperA2size

                                              sheetsize = "A2"

                                          Case swDwgPaperSizes_e.swDwgPaperA3size

                                              sheetsize = "A3"

                                          Case swDwgPaperSizes_e.swDwgPaperA4size

                                              sheetsize = "A4"

                                          Case swDwgPaperSizes_e.swDwgPaperA4sizeVertical

                                              sheetsize = "A4V"

                                          Case swDwgPaperSizes_e.swDwgPapersUserDefined

                                              sheetsize = "UserDefined"

                                      End Select

                                      Debug.Print ("Sheet Size: " & sheetsize)

                           

                                  End If

                                  Get_SheetSize = sheetsize

                              End Function