Skip to main content
1-Visitor
May 27, 2020
Solved

Creo automation: start Creo with trail-file by e.g. python command

  • May 27, 2020
  • 2 replies
  • 4928 views

I want to do some automated Tasks in Creo controlled by a python script.

 

I prefer a simple solution without the need of extra Software (creoson / creopyson).

 

What works is to start Creo with a Batch file or from cmd with the Trail-file. (parametric.exe .psf Trail.txt)

But when I start Creo like this from within python, the Trail file is ignored. I don't know why.

 

I use the external Analysis and .csv files to change Parameters and get measurements. The csv-files are read/written with the python script.

 

Is there something in Creo, which blocks the Trail-file when started from python?

I think it would be the same, if I use a different programming language.

 

I've tried the following:

 

batch-file:

"C:\Program Files\ptc\Creo 4.0\M070\Parametric\bin\parametric.exe" "C:\Program Files\ptc\Creo 4.0\M070\Parametric\bin\parametric1.psf" M:\test_trail.txt

 

python commands:

start with batch file:

import os
import subprocess

os.chdir(pathlib.Path(r"C:\Program Files\ptc\Creo 4.0\M070\Parametric\bin"))
test = subprocess.Popen(r"M:\start_creo_with_trail.bat")

 start directly:

import os
import subprocess

os.chdir(pathlib.Path(r"C:\Program Files\ptc\Creo 4.0\M070\Parametric\bin"))
test = subprocess.Popen(["parametric.exe","parametric1.psf","M:\test_trail.bat"])

 

Best answer by MartinHanak

Additional note:

Maybe M:\test_trail.txt is causing problem, i.e. mapped drive M:. Try moving trail file to C: drive.

2 replies

24-Ruby III
May 27, 2020

Hi,

below you can find information related to my testing...

---

Python 3.6

---

I asked Google ... python start batch script

... and used information available on https://datatofish.com/batch-file-from-python/ page.

---

I created simple trail file ... it contains two commands:

1.] Working Directory setting (myassembly.asm is located in it)

2.] File > Open > myassembly.asm

---

mh_parametric.bat

 

 off
"E:\PTC\Creo4_M120\Creo 4.0\M120\Parametric\bin\parametric.exe" "E:\PTC\Creo4_M120\Creo 4.0\M120\Parametric\bin\parametric.psf" E:\users\Anaconda3_private\mh_trail.txt

 

---

mh_launch_creo.py

 

import subprocess
subprocess.call([r'E:\users\Anaconda3_private\mh_parametric.bat'])

 

---

I can run successfully following command from Command Prompt window

 

python.exe E:\users\Anaconda3_private\mh_launch_creo.py

 

---

 

24-Ruby III
May 27, 2020

Additional note:

Maybe M:\test_trail.txt is causing problem, i.e. mapped drive M:. Try moving trail file to C: drive.

ME891-VisitorAuthor
1-Visitor
May 27, 2020

Hi MartinHanak,

 

with your help I've found out why it didn't worked. Thanks!

 

For coding I use Visual Studio Code with python Extension together with miniconda.

One of it's Advantages is the inbuilt terminal. But here it's the root cause for the failure.

 

Using Anaconda Prompt the Code works as it should.

But I don't know in Detail, why VS Code runs this python command / cmd command different.

17-Peridot
May 27, 2020

Trail Files... 🙄

 

In CREOSON / CREOPYSON ... did the connection : start_creo not work?

 

Dave