Skip to main content
1-Visitor
December 17, 2018
Question

Python script generate data matrix code

  • December 17, 2018
  • 1 reply
  • 4160 views
Hello!

I have a script which generates datamatrix code - dmc- in dxf format and stores it on the defined location on hard disk. For now script is static, which means it generates data matrix code according to parameters which are defined in script itself. My question is, if it would be possible to somehow connect python script with the current session in Creo 3.0 to get file name and generate data matrix code accordingly? If that would be possible, my next question is if there is any option to run python script with mapkey.

If none of thie option is feasible, can someone suggest me which approach of genereating dmc would be possible. I also have some knowedge of vba and javascript.

Thank you!

1 reply

16-Pearl
December 17, 2018

Kekec14,

 

You can run an external program via a mapkey using the @System command.  The following will launch a python command and return control back to Creo Parametric:

 

mapkey dmc @MAPKEY_NAMECreate Data Matrix Code;\
mapkey(continued) @MAPKEY_LABELCreate Data Matrix Code;\
mapkey(continued) @SYSTEMstart \/min \
mapkey(continued) C:\\PTC\\scripts\\dmc.py;

 

The above assumes your PC has an association with the .py extension that will run the program (vs. editing it).  It may be safer to run a .bat script to launch the python program instead of relying on the PC to have an association already.

 

If your script just needs the filename, there are many ways of exporting that data to disk that your program can then read.  A simple "model information" saved to disk is one.

 

Since you're familiar with JavaScript, you may wish to look at the java scripting capabilities of Creo Parametric.

 

Regards,

 

Dan N.

kekec141-VisitorAuthor
1-Visitor
December 19, 2018

Hello Dan!

 

Thank you for your solution. I compiled .py file into .exe, so now I am able to run it with your mapkey. What would be the mapkey to generate list of parts, drawings and assemblies in current session in simple .txt file. According to list of files my python script would be able to generate dxf of dmc.

 

Thank you,

 

Regards!

16-Pearl
December 19, 2018

In Creo Parametric 4.0, you can use FILE > MANAGE SESSION > OBJECT LIST and you have the option to save the list to disk.  The filename is names.inf.#.  You will need to parse the file to get the necessary filenames, as well as filtering out any unwanted filenames for skeletons, generics, and such if necessary.

 

Regards,

 

Dan N.