VBA, VB.NET For Creo

Module] Crero VBA Start Module

ToolBOX01 2025. 1. 20. 08:36
반응형

Module name : CreoVBAStart01
Sub Name : CreoConnt01()

Option Explicit
Public asynconn As New pfcls.CCpfcAsyncConnection
Public conn As pfcls.IpfcAsyncConnection
Public BaseSession As pfcls.IpfcBaseSession
Public Model As pfcls.IpfcModel
Public Sub CreoConnt01()
    On Error GoTo ErrorHandler '// Setting up an error handler
    
    	'// Creo 연결 설정
    	Set conn = asynconn.Connect(Null, Null, Null, Null)
    
    	'// Creo Connection Settings
    On Error ResumMe Next '// Keep code execution going even when an exception occurs
    	Set BaseSession = conn.Session
    	If Err.Number <> 0 Then
        	MsgBox "Failed to import Creo session. Check your connection status." & vbCrLf & _
            	   "Error message: " & Err.Description, vbCritical, "error"
        	Err.Clear
        	Exit Sub
    	End If
    On Error GoTo ErrorHandler '// Revert back to default error handling
    
    	'// Get current Model
    	Set Model = BaseSession.CurrentModel
    	If Model Is Nothing Then
        	MsgBox "There are currently no active Creo Models", vbInformation, "alarm"
        	Exit Sub
    	End If     
    	'// MsgBox "Creo connection and Model verification complete", vbInformation, "success"

ErrorHandler:
   ' ToolkitNotFound Special handling of error messages
    If InStr(Err.Description, "XToolkitNotFound") > 0 Then
        MsgBox "Make sure Creo is running.", vbCritical, "error"
        Exit Sub
    End If
End Sub

 

How to use . .

Option Explicit
Sub FolderPartList01()
    On Error GoTo RunError
    Application.EnableEvents = False

    '// Module Name : CreoVBAStart
    Call CreoVBAStart.CreoConnt01
    
    debug.Print Model.FileName

Public BaseSession As pfcls.IpfcBaseSession :  You can use BaseSession variables
Public model As pfcls.IpfcModel : You can use model variables

Please create repetitive codes as libraries and use them. Please share the library with other users.

by korealionkk@gmail.com