Reply
Solved! Go to solution

How to set custom paperprint in DraftPrintUtility?

[ Edited ]

Hi guys,

 

Im trying to create a macro that prints the current draft in an especific printer depending on the size of the sheet.

 

When the sheet is in A4 or A3 I send it to one printer; if it's in A2, A1 or A0 I send it to a Plotter

 

Due Solid Edge DraftPrintUtility PaperSize Constants doesn't include A2, A1 or A0, I have to define Paper Size as Custom and then I have to indicate de PaperHeight an PaperWidth.

 

To define PaperHeight and PaperWidth I check the Sheet.SheetSetup.SheetHeight and Sheet.SheetSetup.SheetWidth.

 

But when I inspect the values of PaperHeight and PaperWidth they don't have the desired values.

 

Here is the code:

 

Dim objApp As SolidEdgeFramework.Application = Nothing
Dim objdraft As SolidEdgeDraft.DraftDocument = Nothing
Dim objsheet As SolidEdgeDraft.Sheet = Nothing
Dim DraftPrinter as SolidEdgeDraft.DraftPrintUtility=Nothing objApp = GetObject(, "SolidEdge.Application") objdraft = objApp.ActiveDocument 'Defined in other objsheet = objdraft.Sheets.Item("DFT") DraftPrinter.Printer = "KONICA Oficina" DraftPrinter.PrintAsBlack = True DraftPrinter.AutoOrient = False DraftPrinter.SheetsPerPage = SolidEdgeDraft.DraftPrintSheetsPerPageConstants.igSingleSheet DraftPrinter.BestFit = False DraftPrinter.SingleSheetScale = 1.0 Dim TamañoHoja As String = objsheet.SheetSetup.SheetSizeOption Select Case TamañoHoja Case 28, 29 'A4 DraftPrinter.PaperSize = SolidEdgeDraft.DraftPrintPaperSizeConstants.igDraftPrintPaperSize_A4 Case 30, 31 'A3 DraftPrinter.PaperSize = SolidEdgeDraft.DraftPrintPaperSizeConstants.igDraftPrintPaperSize_A3 Case Else 'A2, A1 or A0 Landscape or Portrait DraftPrinter.Printer = "Plotter Oficina" DraftPrinter.PrintAsBlack = False Dim Ancho As Double = Nothing Dim Alto As Double = Nothing Ancho = objsheet.SheetSetup.SheetWidth * 1000 + 20 '*1000 due sheetwidth is in meters. +20 to leave some margin. Alto = objsheet.SheetSetup.SheetHeight * 1000 + 20 '*1000 due sheetwidth is in meters. +20 to leave some margin. If Ancho > Alto Then DraftPrinter.Orientation = SolidEdgeDraft.DraftPrintOrientationConstants.igDraftPrintLandscape Else DraftPrinter.Orientation = SolidEdgeDraft.DraftPrintOrientationConstants.igDraftPrintPortrait End If DraftPrinter.PaperSize = SolidEdgeDraft.DraftPrintPaperSizeConstants.igDraftPrintPaperSize_Custom DraftPrinter.PaperHeight = Alto DraftPrinter.PaperWidth = Ancho End Select DraftPrinter.AddSheet(objsheet) DraftPrinter.PrintOut()

 

Thanks.

 

-Héctor Pelayo

Héctor Pelayo Izquierdo
Engineering Department, JAE Ingeniería y Desarrollos, S.L.
Solid Edge ST9 MP5 | NX 9
Development: VB.NET
2 REPLIES
Solution
Solution
Accepted by topic author Hector
‎08-26-2015 04:32 AM

Re: How to set custom paperprint in DraftPrintUtility?

[ Edited ]

Hi Héctor,

I made a Macro (In VBA for excel) with the same purpose. It may be a little different than you idea but maybe you "ll find your solution in the following example (I actualy copied and deleted some of my irrelevant code.) So maybe this example has some errors, but i hope it makes the algorithm clear.

Note the last argument of the printout method: papersize:=...
These papersizes are determined by the printers manufacturer and is different for each printer. I found an executable on the web to get thes papersize constants for our printers, but i lost it. I can give you an other reference though:


http://bytes.com/topic/visual-basic-net/answers/386417-get-available-paper-sizes-installed-printers

 

Dim oActDoc As SolidEdgeDocument 'SolidEdgeDocument

Dim oDFT As SolidEdgeDraft.DraftDocument 'SolidEdgeDraft.DraftDocument

Dim oDrawView As SolidEdgeDraft.DrawingView ' SolidEdgeDraft.DrawingView

Dim oSheetSetup As SolidEdgeDraft.SheetSetup 'SolidEdgeDraft.SheetSetup

Dim oActiveDocument As SolidEdgeDocument 'SolidEdgeDocument

Dim NumberOfCopies As Integer 'Number of copies to be printed
Dim PaperSize As PaperSizeConstants ' Papersize constants by SE

Dim printer1 As string
Dim printer2 As string

printer1 = pr_CADcolor_PCL5 'Printer that prints A4 and A3
printer2 = pr_T1300_HPGL2 'Printer that prints A2, A1 and A0
set oActDoc = oSE.ActiveDocument If oActDoc.Type = igDraftDocument Then 'for draft file only Set oDFT = oActDoc PaperSize = oDFT.ActiveSheet.SheetSetup.SheetSizeOption Select Case PaperSize Case 28 'A4-V Call oDFT.PrintOut(Printer:=printer1, Numcopies:=NumberOfCopies,_
Orientation:=1, PaperSize:=9) Case 29 'A4-H Call oDFT.PrintOut(Printer:=printer1, Numcopies:=NumberOfCopies,_
Orientation:=2, PaperSize:=9) Case 30 'A3-V Call oDFT.PrintOut(Printer:=printer1, Numcopies:=NumberOfCopies,_
 Orientation:=1, PaperSize:=8) Case 31 'A3-H Call oDFT.PrintOut(Printer:=printer1, Numcopies:=NumberOfCopies,_
 Orientation:=2, PaperSize:=8) Case 32 'A2-V Call oDFT.PrintOut(Printer:=printer2, Numcopies:=NumberOfCopies,_
 Orientation:=1, PaperSize:=66) Case 33 'A2-H Call oDFT.PrintOut(Printer:=printer2, Numcopies:=NumberOfCopies,_
 Orientation:=2, PaperSize:=66) Case 34 'A1-V Call oDFT.PrintOut(Printer:=printer2, Numcopies:=NumberOfCopies,_
 Orientation:=1, PaperSize:=2058) Case 35 'A1-H Call oDFT.PrintOut(Printer:=printer2, Numcopies:=NumberOfCopies,_
 Orientation:=2, PaperSize:=2058) Case 36 'A0-V Call oDFT.PrintOut(Printer:=printer2, Numcopies:=NumberOfCopies,_
 Orientation:=1, PaperSize:=2059) Case 37 'A0-H Call oDFT.PrintOut(Printer:=printer2, Numcopies:=NumberOfCopies,_
 Orientation:=2, PaperSize:=2059) End Select End If

 I hope I helped you with this reply,
Kr,
David

Re: How to set custom paperprint in DraftPrintUtility?

Thanks David.

As you said "I've found the solution in you example" LOL

I've tried to print some drafts in PDF Printer with differents paper sizes and it works perfect.

Thanks again, David.
Héctor Pelayo Izquierdo
Engineering Department, JAE Ingeniería y Desarrollos, S.L.
Solid Edge ST9 MP5 | NX 9
Development: VB.NET