본문 바로가기
  • 환영 합니다 ! Welcome!
VBA For Creo

IpfcBaseSession.RetrieveModel()

by ToolBOX01 2022. 9. 29.
반응형

■Harddisk 파일 -> Session으로 가져오기

작업폴더에 있는 Creo 파일을  Creo session으로 가져 옵니다. 응용을 하면 Cell에 있는 파일 이름으로

Creo 파일을 session으로 가져 옵니다. ipfcwindow () 함수를 이용하여, Creo 파일을 Open 할 수 있습니다.

 

********************************************************************************************************

Sub HardiskFileOpen()

On Error GoTo RunError
     
        Dim asynconn As New pfcls.CCpfcAsyncConnection
        Dim conn As pfcls.IpfcAsyncConnection: Set conn = asynconn.Connect("", "", ".", 5)
        Dim oSession As pfcls.IpfcBaseSession: Set oSession = conn.Session
        Dim oModel As IpfcModel
        
        Dim oCreateModelDescriptor As New CCpfcModelDescriptor
        Dim oModelDescriptor As IpfcModelDescriptor
        Set oModelDescriptor = oCreateModelDescriptor.CreateFromFileName("post_base.drw")
        
        Set oModel = oSession.RetrieveModel(oModelDescriptor)  '// Session으로 모델 불러오기
        oModel.Display   '// 모델 활성하기


        MsgBox oModel.Filename
               
        conn.Disconnect (2)
       
        'Cleanup
        Set asynconn = Nothing
        Set conn = 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