oPrintMgr.GetSheetRange is not working

oPrintMgr.GetSheetRange is not working

saeplY470
Participant Participant
600 Views
3 Replies
Message 1 of 4

oPrintMgr.GetSheetRange is not working

saeplY470
Participant
Participant

I have written a script that will convert a drawing to XPS format and it's working well.  The problem is that if I have a drawing with 2 or more sheets only the first sheet is converted to XPS as if it's the only sheet in the drawing.  Here is my code, any help would be appreciated

Sub Main()
'Creates a DXF copy of the drawing in the same directory
'as the drawing


   ' Set a reference to the print manager object of the active document.
   ' This will fail if a drawing document is not active.
    Dim oPrintMgr As DrawingPrintManager
    oPrintMgr = ThisApplication.ActiveDocument.PrintManager
    
    oPrintMgr.Printer = "Microsoft XPS Document Writer"
    
    ' Set to print in gray
    oPrintMgr.ColorMode = kPrintGrayScale
    
    ' Set to print using portrait orientation.
    oPrintMgr.Orientation = kLandscapeOrientation
    
    ' Set the paper size.
    oPrintMgr.PaperSize = kPaperSizeA3
    
    ' Set to print full scale.
    oPrintMgr.ScaleMode = kPrintBestFitScale
    
    ' Change the number of copies to 1.
    oPrintMgr.NumberOfCopies = 1
	
    ' Get and set the current sheet range.
    Dim iFromSheet As Long
    Dim iToSheet As Long
    Call oPrintMgr.GetSheetRange(iFromSheet, iToSheet)
        
    ' Change the print range to print all sheets.
    oPrintMgr.PrintRange = kPrintSheetRange
    Call oPrintMgr.SetSheetRange(iFromSheet,iToSheet)
    
    'Set File Name and Path
    path_and_name = ThisDoc.PathAndFileName(False) ' without extension
	
    ' Submit the print.
    oPrintMgr.PrintToFile(path_and_name & ".xps")
End Sub

 

0 Likes
601 Views
3 Replies
Replies (3)
Message 2 of 4

Mike.Wohletz
Collaborator
Collaborator

try this out and see if it works for you:

 

Sub Main()
'Creates a DXF copy of the drawing in the same directory
'as the drawing


   ' Set a reference to the print manager object of the active document.
   ' This will fail if a drawing document is not active.
    Dim oPrintMgr As DrawingPrintManager
    oPrintMgr = ThisApplication.ActiveDocument.PrintManager
    
    oPrintMgr.Printer = "Microsoft XPS Document Writer"
    
    ' Set to print in gray
    oPrintMgr.ColorMode = kPrintGrayScale
    
    ' Set to print using portrait orientation.
    oPrintMgr.Orientation = kLandscapeOrientation
    
    ' Set the paper size.
    oPrintMgr.PaperSize = kPaperSizeA3
    
    ' Set to print full scale.
    oPrintMgr.ScaleMode = kPrintBestFitScale
    
    ' Change the number of copies to 1.
    oPrintMgr.NumberOfCopies = 1
	
    ' Get and set the current sheet range.
    ' Dim iFromSheet As Long
    ' Dim iToSheet As Long
    ' Call oPrintMgr.GetSheetRange(iFromSheet, iToSheet)
        
    ' Change the print range to print all sheets.
    oPrintMgr.PrintRange = kPrintAllSheets
    ' Call oPrintMgr.SetSheetRange(iFromSheet,iToSheet)
    
    'Set File Name and Path
    path_and_name = ThisDoc.PathAndFileName(False) ' without extension
	
    ' Submit the print.
    oPrintMgr.PrintToFile(path_and_name & ".xps")
End Sub

 

0 Likes
Message 3 of 4

saeplY470
Participant
Participant

Is the only difference the use of kPrintAllSheets?

 

I have tried that and it didn't work, but i'll try again.

0 Likes
Message 4 of 4

Mike.Wohletz
Collaborator
Collaborator

Commenting out the getting range items and changing it to printallsheets is all I have done and it worked for me.  If you want to go by the sheet range you can use something like the following;

 

Dim oDrawDoc as DrawingDocument 
oDrawDoc = ThisApplication.ActiveDocument

Call oPrintMgr.SetSheetRange(1,oDrawDoc.Sheets.Count)

 it is my understanding that the GetSheetRange is not going to give you the number of sheets, but rather what the current values are for the sheet range. 

 

0 Likes