본문 바로가기
  • Welcome!
VBA, VB.NET For Creo

Output the currently active 3D model name

by ToolBOX01 2025. 3. 11.
반응형

The name of the currently active Part file is displayed in the message window. The name of the currently active Aseebmbly file is displayed in the message window.
(The drawing file name cannot be displayed in the message window.)

To start the code, copy the starting Template code to create the code.

 

Installation and setup for using Creo VBA

1. Creo VBA API installationSelect "API Toolkits > VBA API . . ." to install.2. Setting up "pro_comm_msg.exe"Facilitates communication between the executable xtop.exe and asynchronous Pro/TOOLKIT applicationsFor your application to communicate wi

tool-2020.tistory.com

 

▷ code

Open the creo model and run the code. You should have basic knowledge of Excel VBA.

Option Explicit

Sub GetModelName()

	Application.EnableEvents = False
	On Error GoTo RunError
    
    	Dim asynconn As New pfcls.CCpfcAsyncConnection
    	Dim conn As pfcls.IpfcAsyncConnection
    	Dim BaseSession As pfcls.IpfcBaseSession
    	Dim Model As IpfcModel

        Set conn = asynconn.Connect("", "", ".", 5)
        Set BaseSession = conn.session
        Set Model = BaseSession.CurrentModel
    
        MsgBox Model.FileName, 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

Get the model name using the function IpfcModel.

Property  .FileName   as String
The model file name in "name"."type" format.

 

 

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