Excel 매크로용 VBA를 사용하여 PCF 파일을 읽고 열려 있는 활성 도면 모델을 인쇄하는 예제 코드
Creo Parametric에서 Excel용 Creo VBA를 사용하여 드로잉 파일을 인쇄하는 방법
PCF 파일을 읽고 열려 있는 드로잉 파일의 지정된 범위의 드로잉 시트를 인쇄하는 Creo VB API 예제 코드
1. PCF(플롯 구성 파일)를 읽어 드로잉을 인쇄하는 Creo Excel VBA 작업 예제 코드:
Private Function PlotSheetRangeWithPCF(ByRef IBaseSession As pfcls.IpfcBaseSession, ByRef Drawing As IpfcDrawing, ByVal PcfFileName As String, ByVal StartSheet As Integer, ByVal EndSheet As Integer)
IBaseSession.SetConfigOption("display_planes", "no")
IBaseSession.SetConfigOption("display_axes", "no")
IBaseSession.SetConfigOption("datum_point_display", "no")
IBaseSession.SetConfigOption("display_coord_sys", "no")
' Place your company standard plot configuration files (*.pcf) in a directory and
' set it's full path as value to Creo configuration option pro_plot_config_dir.
Sub PrintDrawingWithPCF()
On Error GoTo RunError
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 Creo
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:\ptc\creo_stds\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 creo
conn.Disconnect (2)
'Cleanup
Set asynconn = Nothing
Set conn = Nothing
Set session = Nothing
Set oModel = Nothing
Exit Sub
RunError:
If Err.Number <> 0 Then
MsgBox "Process Failed : Unknown error occurred." + Chr(13) + _
"Error No: " + CStr(Err.Number) + Chr(13) + _
"Error: " + Err.Description, vbCritical, "Error"
If Not conn Is Nothing Then
If conn.IsRunning Then
conn.Disconnect (2)
End If
End If
End I
End Sub
2. PCF(플롯 구성 파일)를 읽어서 지정된 범위의 드로잉 시트 를 인쇄하는 Creo VB API 작업 예제 코드 :
Private Function PlotSheetRangeWithPCF(ByRef IBaseSession As pfcls.IpfcBaseSession, ByRef Drawing As IpfcDrawing, ByVal PcfFileName As String, ByVal StartSheet As Integer, ByVal EndSheet As Integer)
IBaseSession.SetConfigOption("display_planes", "no")
IBaseSession.SetConfigOption("display_axes", "no")
IBaseSession.SetConfigOption("datum_point_display", "no")
IBaseSession.SetConfigOption("display_coord_sys", "no")
' Place your company standard plot configuration files (*.pcf) in a directory and
' set it's full path as value to Creo configuration option pro_plot_config_dir.
' Example: pro_plot_config_dir C:\Engineering_Standards\Creo_Standards\Plot_configs\
' Creo will find any *.pcf file just by its file name if it exists in one of the below mentioned locations
' 1. In Current Working Directory
' 2. In Directory set by configuration option pro_plot_config_dir
' 2. In <Creo Common Files>\text\plot_config Directory
Dim pcfOptions As IpfcPrinterPCFOptions
Dim printerOptions As IpfcPrinterInstructions
'pfcFileName length should be max 32 chars excluding file extension.
'If exceeds 32 chars, results in exception xToolkitNotFound / xToolkitStringTooLong
pcfOptions = IBaseSession.GetPrintPCFOptions(PcfFileName, Drawing)
printerOptions = (New CCpfcPrinterInstructions).Create()
printerOptions.ModelOption = pcfOptions.ModelOption
printerOptions.PlacementOption = pcfOptions.PlacementOption
printerOptions.PrinterOption = pcfOptions.PrinterOption
printerOptions.WindowId = IBaseSession.GetModelWindow(Drawing).GetId()
printerOptions.ModelOption.Sheets = EpfcPrintSheets.EpfcPRINT_SELECTED_SHEETS
printerOptions.ModelOption.FirstPage = StartSheet
printerOptions.ModelOption.LastPage = EndSheet
'Set required output print paper size.
'Do this only if you want any sheet size to be plot to single paper size.
Dim printSize As IpfcPrintSize
printSize = (New CCpfcPrintSize).Create()
printSize.PaperSize = EpfcPlotPaperSize.EpfcA4SIZEPLOT
printerOptions.PrinterOption.PaperSize = printSize
Dim mdl As IpfcModel
mdl = CType(Drawing, IpfcModel)
printerOptions.ModelOption.Mdl = mdl
printerOptions.PrinterOption.FileName = mdl.InstanceName
Dim ExportInstr As IpfcExportInstructions
ExportInstr = CType(printerOptions, IpfcExportInstructions)
mdl.Export(mdl.InstanceName, ExportInstr)
End Function
3. 일반 POSTSCRIPT용 PCF 파일 예 : ( postscript.pcf )
plotter POSTSCRIPT
button_name Generic Postscript
button_help Print to any printer that supports generic postscript format.
plot_drawing_format YES default
plot_segmented NO default
plot_roll_media NO default
plot_label NO default
plot_handshake software default
create_separate_files NO default
plot_with_panzoom NO default
rotate_plotting NO default
allow_file_naming YES
plot_name NO
interface_quality 3 default
plot_destination file default
pen_table_file table.pnt
plot_sheets current default
paper_size A4 default
paper_outline NO default
plot_clip NO default
plot_area NO default
plot_stroke_text YES
'VBA For Creo' 카테고리의 다른 글
작업공간에 있는 *.prt 타입 파일들의 이름을 모두 표시 합니다 (0) | 2022.09.05 |
---|---|
# 5 IpfcBaseSession : session에 있는 모델들 이름 모두 표시 (0) | 2022.09.04 |
Part 파일을 jpg 이미지로 저장 하기 (0) | 2022.09.02 |
현재 활성화된 폴더의 하위폴더 알아보기 (0) | 2022.08.30 |
현재 활성화된 폴더 이름 알아보기 (0) | 2022.08.28 |