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

VBA Start Template

by ToolBOX01 2023. 2. 5.
반응형

VBA  프로그램 시작을 아래 코드를 기반으로 생성 합니다  

Download :

VBA START TEMPLATE 01 .xlsm
0.01MB

▶ 전체 코드

Option Explicit
Public asynconn As New pfcls.CCpfcAsyncConnection
Public conn As pfcls.IpfcAsyncConnection
Public oSession As pfcls.IpfcBaseSession
Public oModel As IpfcModel
Public oSolid As IpfcSolid
Public Sub Creo_Connect()

    Application.EnableEvents = False
    
    '//////////////////////////////////////////////////////////////////////////////////////////////////////
    '// Creo Connect Check
    '//////////////////////////////////////////////////////////////////////////////////////////////////////
    On Error Resume Next
    Set conn = asynconn.Connect("", "", ".", 5)
    
        If conn Is Nothing Then
        
           MsgBox "Error occurred while starting new Creo Parametric Session!", vbInformation, "www.idt21c.com"
           Exit Sub
           
        End If
     '//////////////////////////////////////////////////////////////////////////////////////////////////////
    
    Set oSession = conn.Session


End Sub

Sub main01()

    Call Creo_Connect
    
    On Error GoTo RunError
    
    '// Current WorkFolder Name
    Cells(4, "E") = LCase(oSession.GetCurrentDirectory)
    
    '// Current Model Name
    Set oModel = oSession.CurrentModel
  
    If oModel Is Nothing Then
    
        MsgBox "No models are active!", vbInformation, "www.idt21c.com"

       Else
        
        Cells(5, "E") = LCase(oModel.Filename)

     End If   

    '// Disconnect with Creo
    conn.Disconnect (2)
    
    '// Cleanup
    Set asynconn = Nothing
    Set conn = Nothing
    Set oSession = 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 If


End Sub