반응형
VBA 프로그램 시작을 아래 코드를 기반으로 생성 합니다
Download :
▶ 전체 코드
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
'VBA For Creo' 카테고리의 다른 글
함께 VBA 만들기 #6 - Parameter 값 모델에 저장하기 (0) | 2023.02.08 |
---|---|
함께 VBA 만들기 #5 - Material 지정 및 무게 계산 (0) | 2023.02.08 |
함께 VBA 만들기 #4 - Creo 3D 모델 정보 보기 (0) | 2023.02.05 |
함께 VBA 만들기 #3 - Creo 3D 모델 정보 보기 (0) | 2023.02.03 |
마이크로소프트(MS)가 인공지능(AI) 챗봇 기능 기반의 제품을 출시 (0) | 2023.02.03 |