Skip to main content
6-Contributor
April 26, 2023
Question

Connecting into Creo using Python

  • April 26, 2023
  • 2 replies
  • 8577 views

Hello all ,

 

I am trying to connect into Creo using a python code to extract the parameters into BOMs..

First off has anyone successful done this?? 

I believe it is possible , However I maybe missing a file or module or not using the correct connection command.

 

Here is  the current setup.

-Creo 6.0.5.1

-Python Latest version

-All modules update to date.

-I have all the toolkit API installed.

-pro_comm_msg in environment variables

- I have preferred to used win32com.client module to make connection but it has failed to make the connection.

- I have also tried Creoson third party software to  make the connection. I was able to connect  to the server and Creo but failed to extract the parameters .it just stated no attributes to get...As there no offical help on this software it is hard to get help on this.

 

So If anyone can provide code of how they establish a connection and was able to send commands/extracted data would be helpful.

 

Thanks.

2 replies

14-Alexandrite
April 26, 2023

Creoson relies on J-Link so the first thing is to run ptcsetup and confirm you have the J-Link packages installed. Also, if I remember correctly the Creoson tool only allows one way communication (it's just using JSON requests) so you can get the data out of Creo but you will have to do something like a mapkey or playing a trail file to put the data back in to Creo.

6-Contributor
April 26, 2023

Hello TractorGuy,

 

Thanks for quick reply. I am only look to extract the parameters of the parts. listed the code below. nad the result from command prompt using  creopyson.

Perhaps someone see when I am wrong.

 

import creopyson

def is_creo_running():
"""
Check if Creo Parametric is running.

Returns:
bool: True if Creo Parametric is running, False otherwise.
"""
try:
c = creopyson.Client()
c.connect()
c.disconnect()
return True
except:
return False

try:
print("Connecting to Pro/ENGINEER (Creo) Parametric...")
if not is_creo_running():
print("Creo Parametric is not running.")
exit()

# Create a Creo session using creopyson.Client()
c = creopyson.Client()
c.connect()
c.creo_set_creo_version(6)

print("Connection to Pro/ENGINEER (Creo) Parametric established successfully!")

# Get the sessionId from the client object
sessionId = c.sessionId
print("Session ID: " + str(sessionId))

# Execute Creo CLI command to retrieve parameter list from the model
result = c.creo_execute_command("parm_list")

if result["success"]:
param_list = result["message"]
print("Parameter list: ")
for param in param_list:
param_name = param["name"]
param_file = param["file"]
print(f"Name: {param_name}, File: {param_file}")
else:
print("Failed to retrieve parameter list.")

# Disconnect from Pro/ENGINEER (Creo) Parametric
c.disconnect()

print("Pro/ENGINEER (Creo) Parametric session closed successfully!")
except Exception as e:
print("Error: ", e)

 

 

command prompt printouts....

 

C:\python_code>python 202.py
Connecting to Pro/ENGINEER (Creo) Parametric...
Connection to Pro/ENGINEER (Creo) Parametric established successfully!
Session ID: -2295100368324320170
Error: 'Client' object has no attribute 'creo_execute_command'

 

The model does have attributes and it can seem to get them or carry out the command?

 

anyone seen this error before?

 

24-Ruby III
April 26, 2023
6-Contributor
April 27, 2023

Morning Martin,

 

Thanks for the information. I have been able to connect into Creo use Cresoson and creopython. I have been able to export single part or assembly paraMeters. Do you or anyone know what is the command for a  user to export the full parameters of a assembly.? The BOM commands seem to failed for some reason.

 

Thanks

24-Ruby III
April 27, 2023