본문 바로가기
  • Welcome!
VBA For Creo

작업 폴더에 있는 Drawing 파일 인쇄 ver 0.1 - PCF

by ToolBOX01 2022. 10. 13.
반응형
Sub PrintDrawingWithPCF()

Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection
Dim CreoSession As pfcls.IpfcBaseSession
Dim CreoCurrentModel As pfcls.IpfcModel
'Make an asynchronous connection with Pro/ENGINEER
Set conn = asynconn.Connect("", "", ".", 5)
'Get the current session
Set CreoSession = conn.session
'Show the current Working Directory
MsgBox "This is the current Working Directory: " & vbCrLf & CreoSession.GetCurrentDirectory
Set CreoCurrentModel = CreoSession.CurrentModel
'Show the name of the Pro/E Model in a messagebox
MsgBox "Model name = " & CreoCurrentModel.Filename
Set oWindow = CreoSession.GetModelWindow(CreoCurrentModel)

'Activate the new window before printing
oWindow.Activate
Dim PrinterInstrCreate As CCpfcPrinterInstructions
Dim PrinterInstr As IpfcPrinterInstructions
Dim printerPCFOptionsCreate As CCpfcPrinterPCFOptions
Dim printerPCFOptions As IpfcPrinterPCFOptions
Dim creoWindow As IpfcWindow

Set PrinterInstrCreate = New CCpfcPrinterInstructions
Set PrinterInstr = PrinterInstrCreate.Create
Set printerPCFOptionsCreate = New CCpfcPrinterPCFOptions
Set printerPCFOptions = printerPCFOptionsCreate.Create
Set printerPCFOptions = CreoSession.GetPrintPCFOptions("C:\temp\postscript.pcf", CreoCurrentModel)
PrinterInstr.PrinterOption = printerPCFOptions.PrinterOption
PrinterInstr.ModelOption = printerPCFOptions.ModelOption
PrinterInstr.PlacementOption = printerPCFOptions.PlacementOption

'Set SaveToFile = True if a plot file has to be saved to Disk
PrinterInstr.PrinterOption.SaveToFile = True
' Set the output plot file name here
PrinterInstr.PrinterOption.Filename = CreoCurrentModel.InstanceName

'Set SendToPrinter = True if the plot should be directed to Printer
PrinterInstr.PrinterOption.SendToPrinter = True
'Print command should be set to print to a printer if it is not set in the PCF file
PrinterInstr.PrinterOption.PrintCommand = "windows_print_manager \\machine_name\Device_Name"

Set creoWindow = CreoSession.GetModelWindow(CreoCurrentModel)
PrinterInstr.WindowId = creoWindow.GetId
CreoCurrentModel.Export CreoCurrentModel.InstanceName, PrinterInstr

'Disconnect with Pro/ENGINEER
conn.Disconnect (2)
'Cleanup
Set asynconn = Nothing
Set conn = Nothing
Set session = Nothing
Set oModel = Nothing

End Sub