반응형
This is the code to open a model with the Creo file name in the current working folder.
Option Explicit
Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection
Dim oBaseSession As pfcls.IpfcBaseSession
Dim oModel As pfcls.IpfcModel
Dim ws as Worksheet
Dim oModelDescriptorCreate As New CCpfcModelDescriptor
Dim oModelDescriptor As IpfcModelDescriptor
Dim oSession As IpfcSession
Dim oWindow As pfcls.IpfcWindow
Sub Newmodel()
On Error GoTo RunError
'\\ Make an asynchronous connection with Creo
Set conn = asynconn.Connect("", "", ".", 5)
'\\Get the current session
Set oBaseSession = conn.session
'\\Show the current Working Directory
Set ws = ThisWorkbook.Worksheets("Template")
ws.Cells(1, "B") = vbCrLf & oBaseSession.GetCurrentDirectory
'\\ Create a modeldescriptor to the Creo Model
Set oModelDescriptor = oModelDescriptorCreate.CreateFromFileName(ws.Cells(1, "C")) '\\ws.Cells(1, "C") = "korea.prt"
'\\Retrieve the model into the Model handle
Set oModel = oBaseSession.RetrieveModel(oModelDescriptor)
'\\Create a new window which displays the Creo Model
Set oSession = oBaseSession
Call oSession.UIShowMessageDialog(oModel.Filename, Nothing)
Set oWindow = oBaseSession.GetModelWindow(Model)
oWindow.Activate
'Disconnect with Creo
conn.Disconnect (2)
'Cleanup
Set asynconn = Nothing
Set conn = Nothing
Set oBaseSession = Nothing
Set oSession = Nothing
Set oModel = Nothing
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 If
End Sub
by korealionkk@gmail.com
'VBA, VB.NET For Creo' 카테고리의 다른 글
VB API Fundamentals -- VBA 예제 (1) Session 파일 LIST (0) | 2020.12.20 |
---|---|
파일에서 Dimension 값 가져오는 프로그램 (0) | 2020.12.18 |
VB API Fundamentals -- VBA 예제 (3) PART-LIST (0) | 2020.12.14 |
4-2 # Parameter : Part 파일의 모든 매개변수, Type, Value 표시 하기 (0) | 2020.12.11 |
4-4 # Parameter : 매개변수 읽고, 쓰기 (0) | 2020.12.10 |