cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Python for creo automation

sammy1994
11-Garnet

Python for creo automation

Can i use python for automating boring and repeating stuff in creo?? 

Like batch processes(converting to iges/step) and using parameter value as input to filename

ACCEPTED SOLUTION

Accepted Solutions
RPN
17-Peridot
17-Peridot
(To:sammy1994)

Hmm, not Python but Tcl

 

You can read this

Check the "Export Data" section.

Or view this at YouTube

View solution in original post

18 REPLIES 18
RPN
17-Peridot
17-Peridot
(To:sammy1994)

Hmm, not Python but Tcl

 

You can read this

Check the "Export Data" section.

Or view this at YouTube

Hi,

I am able to automate Creo tasks using AutoIT + Creo mapkey + Creo trail file.

As far as know there is no "python API for Creo".


Martin Hanák

Thank you for your response.
How did you learn about how to use creo trail files? I mean there is no
documentation available online

Hi,

I learned by trial and error 🙂


Martin Hanák

Oh great!! I will also do trial and error

Is it necessary to understand everything about trail files to be able to use AutoIT for creo automation??


@sammy1994 wrote:
Is it necessary to understand everything about trail files to be able to use AutoIT for creo automation??

Hi,

I am sorry I do not understand your question ...

So ... I provide some "trail example" created in Creo 2.0. The purpose of the trail file is open Creo file.

1.]

Start Creo, open file, end Creo session. You will get following Creo trail file.

!trail file version No. 1600
!Creo  TM  2.0  (c) 2019 by PTC Inc.  All Rights Reserved.
!Exit Logger data:
!	Process ID: 3444
!	Application: Creo_Parametric
!	Start date&time: 2019/03/15  06:47:31
!	language: czech
!	machine type: x86e_win64
!	datecode: M070
!	Server: NONE
!	Workspace: NONE
!	traceback file: D:\tmp\creo\traceback.log
!end Exit Logger data.
< 0 1.330963 1714 0 0 1123 1920 0 0 1200 13
!mem_use INCREASE Blocks 425261, AppSize 50093379, SysSize 60654184
< 0 1.056000 1515 0 0 891 1920 0 0 1200 13
< 0 1.056000 1364 0 0 891 1920 0 0 1200 13
!%CIWelcome to Creo Parametric 2.0.
!%CDAFX PROFILES_ADV_LL
!Application (EFX_SL50): running DLL-mode user_initialize
!SL: INSTALLPATH "C:\PTC\Creo2_M070\Creo 2.0\Common Files\M070\efx"
!SMARTLibrary 6.0 F000 - 2012130
!Pro/ENGINEER: Creo 2.0 - M070
!Application (EFX_SL50): returned from DLL-mode user_initialize; status is 0
!Application (SmartConfigDll_CREO): running DLL-mode user_initialize
!Application (SmartConfigDll_CREO): returned from DLL-mode user_initialize; status is 0
~ Select `main_dlg_cur` `appl_casc`
~ Close `main_dlg_cur` `appl_casc`
~ Command `ProCmdModelOpen` 
< 2 0.118519 178 0 0 100 1920 0 0 1200 13
~ Trail `UI Desktop` `UI Desktop` `DLG_PREVIEW_POST` \
 `file_open`
~ Select `file_open` `Ph_list.Filelist` 1 `aaa.prt`
~ Trail `UI Desktop` `UI Desktop` `PREVIEW_POPUP_TIMER` \
 `file_open:Ph_list.Filelist:<NULL>`
~ Command `ProFileSelPushOpen@context_dlg_open_cmd` 
!Command ProCmdModelOpenExe was pushed from the software.
!15-Mar-19 06:47:54  Start D:\tmp\creo\aaa.prt.6
!15-Mar-19 06:47:54  End   D:\tmp\creo\aaa.prt.6
~ Select `main_dlg_cur` `appl_casc`
!mem_use INCREASE Blocks 488814, AppSize 74249142, SysSize 88970232
~ Close `main_dlg_cur` `appl_casc`
~ Command `ProCmdExit` 
! Message Dialog: Warning
!               : Creo Parametric will terminate and any unsaved work will be lost.
!               : Do you really want to exit?
~ Trail `UI Desktop` `UI Desktop` `PREVIEW_POPUP_TIMER` \
 `main_dlg_w1:PHTLeft.AssyTree:<NULL>`
~ FocusIn `UI Message Dialog` `yes`
~ Activate `UI Message Dialog` `yes`
!Application (EFX_SL50): running DLL-mode user_terminate
!Application (EFX_SL50): returned from DLL-mode user_terminate
!Application (SmartConfigDll_CREO): running DLL-mode user_terminate
!Application (SmartConfigDll_CREO): returned from DLL-mode user_terminate
!End of Trail File

2.]

 

First two lines represent mandatory header. They are specific for Creo release.

I guess, only first line is necessary.

!trail file version No. 1600
!Creo  TM  2.0  (c) 2019 by PTC Inc.  All Rights Reserved.

3.]

 

Couple of lines at the and of file represent File > Exit command

~ Select `main_dlg_cur` `appl_casc`
!mem_use INCREASE Blocks 488814, AppSize 74249142, SysSize 88970232
~ Close `main_dlg_cur` `appl_casc`
~ Command `ProCmdExit` 
! Message Dialog: Warning
!               : Creo Parametric will terminate and any unsaved work will be lost.
!               : Do you really want to exit?
~ Trail `UI Desktop` `UI Desktop` `PREVIEW_POPUP_TIMER` \
 `main_dlg_w1:PHTLeft.AssyTree:<NULL>`
~ FocusIn `UI Message Dialog` `yes`
~ Activate `UI Message Dialog` `yes`
!Application (EFX_SL50): running DLL-mode user_terminate
!Application (EFX_SL50): returned from DLL-mode user_terminate
!Application (SmartConfigDll_CREO): running DLL-mode user_terminate
!Application (SmartConfigDll_CREO): returned from DLL-mode user_terminate
!End of Trail File

4.]

 

The block of lines "in the middle" of the file represent File > Open command.

Lines starting with ! are comments, you can remove them.

< 0 1.330963 1714 0 0 1123 1920 0 0 1200 13
< 0 1.056000 1515 0 0 891 1920 0 0 1200 13
< 0 1.056000 1364 0 0 891 1920 0 0 1200 13
~ Select `main_dlg_cur` `appl_casc`
~ Close `main_dlg_cur` `appl_casc`
~ Command `ProCmdModelOpen` 
< 2 0.118519 178 0 0 100 1920 0 0 1200 13
~ Trail `UI Desktop` `UI Desktop` `DLG_PREVIEW_POST` \
 `file_open`
~ Select `file_open` `Ph_list.Filelist` 1 `aaa.prt`
~ Trail `UI Desktop` `UI Desktop` `PREVIEW_POPUP_TIMER` \
 `file_open:Ph_list.Filelist:<NULL>`
~ Command `ProFileSelPushOpen@context_dlg_open_cmd` 
!Command ProCmdModelOpenExe was pushed from the software.

5.]

 

Following line is variable, it contains file name ... a.prt in my example.

To prepare "template" trail file for opening any file, I simply replace a.prt with myfilename string

~ Select `file_open` `Ph_list.Filelist` 1 `aaa.prt`

6.]

 

Resulting "template" trail file

!trail file version No. 1600
!Creo  TM  2.0  (c) 2019 by PTC Inc.  All Rights Reserved.
< 0 1.330963 1714 0 0 1123 1920 0 0 1200 13
< 0 1.056000 1515 0 0 891 1920 0 0 1200 13
< 0 1.056000 1364 0 0 891 1920 0 0 1200 13
~ Select `main_dlg_cur` `appl_casc`
~ Close `main_dlg_cur` `appl_casc`
~ Command `ProCmdModelOpen` 
< 2 0.118519 178 0 0 100 1920 0 0 1200 13
~ Trail `UI Desktop` `UI Desktop` `DLG_PREVIEW_POST` \
 `file_open`
~ Select `file_open` `Ph_list.Filelist` 1 `myfilename`
~ Trail `UI Desktop` `UI Desktop` `PREVIEW_POPUP_TIMER` \
 `file_open:Ph_list.Filelist:<NULL>`
~ Command `ProFileSelPushOpen@context_dlg_open_cmd` 
!Command ProCmdModelOpenExe was pushed from the software.

7.] Now I can use "template" trail file in my automation procedure.

If I need to open more than 1 file, I can repeat block doing specific action in trail file.

 

 


Martin Hanák

HI Martin,

do I use this template as a trail file or do I copy these set of lines into my mapkey file or .pro file and run it?

Hi,

I provide trail file, I play it in Creo using Play Trail command. I can't tell you how to create Creo mapkey using trail file content.


Martin Hanák

Thank you for your response 🙂
Actually i was asking if it was necessary to learn about trail files for automating creo using AutoIT
I mean can i use autoit for automation without using trail files??


@sammy1994 wrote:
Thank you for your response 🙂
Actually i was asking if it was necessary to learn about trail files for automating creo using AutoIT
I mean can i use autoit for automation without using trail files??

Hi,

below you can find couple of notes...

1.]

"Automating Creo" topic is too general. It would be better to ask how to automate specific task.

2.]

I think the most functional API for "automating Creo" is Creo Toolkit (you must buy a license).

3.]

You can control Creo using keyboard ALT+key combinations. AutoIT is able to send these combinations to Creo. This enables you to solve some automating tasks.

4.]

Sometimes it is necessary to generate specific trail file and play it to execute automating task.

5.]

Trails files are used even by Creo Toolkit applications.

6.]

There is no simple answer to the question "How to automate Creo".

 


Martin Hanák

Thanks a lot 🙂

Have a look at Creo|SON (http://www.creoson.com/)

I think sending JSON requests to an http server from python is pretty easy ?

FV
17-Peridot
17-Peridot
(To:sammy1994)

if automating with python meant using creo's COM type libraries than it should be doablepython-creo.png

python will import and generate a stab module for whatever is in Creo Type Library but the end result will be the same quite limited functionality as with VB. 

 


@sammy1994 wrote:

Can i use python for automating boring and repeating stuff in creo?? 

Like batch processes(converting to iges/step) and using parameter value as input to filename


 

sammy1994
11-Garnet
(To:FV)

Oh okay! Thank you for your response

Actually - there IS a way to automate Creo with Python. -- "creopyson" was just released as an OpenSource Project that builds on the already OpenSource CREOSON Project.

 

It was JUST released as an interface to CREOSON - which is an OpenSource interface to Creo.

 

Here is the link to creopyson --> https://github.com/Zepmanbc/creopyson (requires CREOSON)

 

Here is the link to CREOSON --> http://www.creoson.com/

 

As the developer/maintainer of CREOSON, we are super impressed by the feedback and contributions to this OpenSource Project!

 

Dave


@DavidBigelow wrote:

Actually - there IS a way to automate Creo with Python. -- "creopyson" was just released as an OpenSource Project that builds on the already OpenSource CREOSON Project.

 

It was JUST released as an interface to CREOSON - which is an OpenSource interface to Creo.

 

Here is the link to creopyson --> https://github.com/Zepmanbc/creopyson (requires CREOSON)

 

Here is the link to CREOSON --> http://www.creoson.com/

 

As the developer/maintainer of CREOSON, we are super impressed by the feedback and contributions to this OpenSource Project!

 

Dave


Hi,

I haven't had time to examine the creopyson yet. David, can you please tell me the benefits of using the python+creopyson over the python+creoson ?


Martin Hanák

Martin,

 

TLDR;

creopyson would be an example of someone (an awesome guy in France) that build a wrapper for CREOSON functions so that a any other user would not have to create their own.  Basically to help other python users "get there faster" for Creo Automation using CREOSON...  Specifically, load library, initialize, and start using - without having to first build the technical bits for the communication first in python to communicate with the CREOSON server.

 

DEEPER EXPLANATION;

CREOSON was developed to be a generic bi-directional service interface into Creo for performing optimized actions via JLINK (e.g. simpler -more obvious- commands, with more options via standard JSON transactions - from ANY language).

 

The core premise of CREOSON was to pass a standard JSON structure over HTTP to a service endpoint - locally or over a network.

 

Because CREOSON uses HTTP as the main interface for transacting requests, ANY language can be used to communicate with it (e.g. VB, Javascript, Java, Python, PHP, etc..) that supports HTTP transactions.

 

Some languages have HTTP interfaces baked-in, others use libraries to perform the actions as optional packages. It is typically up to the user to define the HTTP interface (simple send/receive function that communicates with the CREOSON server) and then write the function(s) for specific CREOSON requests.

 

Typically users create their own function for say opening a model (e.g. myOpenModel(fileName);) that would take an input argument (like fileName) and build the CREOSON JSON request and execute it, then handing the response.  This process would likely be repeated for each function they wanted to use in their application (build a wrapper function that builds and calls CREOSON and responds for their own purpose).

 

So - creopyson is an opensource contribution (from someone in France) who loved CREOSON and wanted to make it even easier to use with python by pre-building all the interfaces in python to call CREOSON - and contributed it for everyone else to use who love phython also.  A pretty awesome OpenSource contribution!

 

 

Announcements


Top Tags