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:
"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
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")
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"])
Solved! Go to Solution.
below you can find information related to my testing...
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
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
import subprocess subprocess.call([r'E:\users\Anaconda3_private\mh_parametric.bat'])
I can run successfully following command from Command Prompt window
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.