반응형
It connects to Creo and writes the names of the model files currently open in the session to an Excel sheet, displays the number of models in a message box, and performs appropriate exception handling when an error occurs, and disconnects after the task is completed to clean up resources. If there are no creo files in the Creo Session, the number of files is displayed as "0".
▷Code
Option Explicit
Sub GetModelNameList()
Application.EnableEvents = False
On Error GoTo RunError
Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection
Dim BaseSession As pfcls.IpfcBaseSession
Dim FileListCount As Integer
Set conn = asynconn.Connect("", "", ".", 5)
Set BaseSession = conn.session
'//Quantity of creo files in session
FileListCount = BaseSession.ListModels().Count
For i = 0 To FileListCount - 1
Cells(i + 3, "C").Value = i + 1
Cells(i + 3, "D").Value = BaseSession.ListModels().Item(i).Filename
Next i
MsgBox "The number of files is:" & FileListCount, vbInformation
conn.Disconnect (2)
'Cleanup
Set asynconn = Nothing
Set conn = Nothing
Set BaseSession = Nothing
Set Model = 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
▷ Creo VBA API : Interface IpfcBaseSession
PTC Help Center
Your browser has DOM storage disabled. Make sure DOM storage is enabled and try again.
support.ptc.com
by : korealionkk@gmail.com
'VBA, VB.NET For Creo' 카테고리의 다른 글
Display all dimension names and values contained in a part file (0) | 2025.03.12 |
---|---|
Output the currently active 3D model name (0) | 2025.03.11 |
Installation and setup for using Creo VBA (0) | 2025.03.10 |
IpfcSurface (0) | 2025.02.01 |
Creo] IpfcModel (0) | 2025.02.01 |