0 Replies Latest reply on Jan 12, 2016 3:18 PM by Mikael Bolduc

    Problem with my print macro

    Mikael Bolduc

      I have a problem with my print macro.

      When I start solidworks and i play my macro , the macro works

      But when I work  on solidworks and after i play macro, the macro didn't work.

      What can be the problem ?

       

      Dim swApp As SldWorks.SldWorks
      Dim Part As SldWorks.ModelDoc2
      Dim swdraw As SldWorks.DrawingDoc
      Dim swSheet As SldWorks.Sheet
      Dim currSheet As String
      Dim sheetNames() As String
      Dim printer As String
      Dim i As Integer
      Dim Papersize As Integer
      Dim boolstatus As Boolean
      Dim longstatus As Long, longwarnings As Long

      Dim SheetWidthMetre As Double
      Dim SheetHeightMetre As Double

      Dim SheetWidthPouce As Double
      Dim SheetHeightPouce As Double

      Const ImprimanteLetter As String = "Brother HL-2040 series"
      Const ImprimanteLedger As String = "Brother MFC-5895CW Printer"

      Sub main()

      Set swApp = Application.SldWorks
      Set Part = swApp.ActiveDoc
      Set swdraw = Part

      currSheet = Part.GetCurrentSheet.GetName
      sheetNames = Part.GetSheetNames

      '**********LETTER 8.5X11**********'
      For i = 1 To Part.GetSheetCount
      Part.ActivateSheet sheetNames(i - 1)

      Set swSheet = swdraw.GetCurrentSheet

      Papersize = swSheet.GetSize(SheetWidthMetre, SheetHeightMetre)
      SheetWidthPouce = SheetWidthMetre / 25.4 * 1000
      SheetHeightPouce = SheetHeightMetre / 25.4 * 1000

      If SheetWidthPouce = 8.5 And SheetHeightPouce = 11 Then
         
      With Part.PageSetup
        .DrawingColor = swPageSetup_AutomaticDrawingColor
        .Orientation = swPageSetupOrient_Portrait 'Landscape / Portrait'
        .ScaleToFit = False
        .scale2 = 100
        .HighQuality = False
        .PrinterPaperSize = 1 '1=8.5X11 ET 3=11X17'
         printer = ImprimanteLetter
      End With
      Part.PrintOut i, i, 1, False, printer, 1, False 'Debug.Print "Sheet: " & sheetNames(i) & "    Sheet Size: " & sheetSize & "    Printer: " & printer
         
      End If

      If SheetWidthPouce = 11 And SheetHeightPouce = 8.5 Then

      With Part.PageSetup
        .DrawingColor = swPageSetup_AutomaticDrawingColor
        .Orientation = swPageSetupOrient_Landscape 'Landscape / Portrait'
        .ScaleToFit = False
        .scale2 = 100
        .HighQuality = False
        .PrinterPaperSize = 1 '1=8.5X11 ET 3=11X17'
         printer = ImprimanteLetter
      End With
      Part.PrintOut i, i, 1, False, printer, 1, False 'Debug.Print "Sheet: " & sheetNames(i) & "    Sheet Size: " & sheetSize & "    Printer: " & printer
         
      End If

      Next i

      '**********LEDGER 11X17**********'
      repeteledger:

      i = i - 1
      If i = 0 Then
      GoTo End2
      End If

      Part.ActivateSheet sheetNames(i - 1)

      Set swSheet = swdraw.GetCurrentSheet

      Papersize = swSheet.GetSize(SheetWidthMetre, SheetHeightMetre)
      SheetWidthPouce = SheetWidthMetre / 25.4 * 1000
      SheetHeightPouce = SheetHeightMetre / 25.4 * 1000

      If SheetWidthPouce = 11 And SheetHeightPouce = 17 Then

      With Part.PageSetup
        .DrawingColor = swPageSetup_AutomaticDrawingColor
        .Orientation = swPageSetupOrient_Portrait 'Landscape / Portrait'
        .ScaleToFit = False
        .scale2 = 100
        .HighQuality = False
        .PrinterPaperSize = 3 '1=8.5X11 ET 3=11X17'
         printer = ImprimanteLedger
      End With
      Part.PrintOut i, i, 1, False, printer, 1, False 'Debug.Print "Sheet: " & sheetNames(i) & "    Sheet Size: " & sheetSize & "    Printer: " & printer
         
      End If

      If SheetWidthPouce = 17 And SheetHeightPouce = 11 Then

      With Part.PageSetup
        .DrawingColor = swPageSetup_AutomaticDrawingColor
        .Orientation = swPageSetupOrient_Landscape 'Landscape / Portrait'
        .ScaleToFit = False
        .scale2 = 100
        .HighQuality = False
        .PrinterPaperSize = 3 '1=8.5X11 ET 3=11X17'
         printer = ImprimanteLedger
      End With
      Part.PrintOut i, i, 1, False, printer, 1, False 'Debug.Print "Sheet: " & sheetNames(i) & "    Sheet Size: " & sheetSize & "    Printer: " & printer

      End If

      GoTo repeteledger

      End2:

      End Sub