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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Python script generate data matrix code

kekec14
3-Newcomer

Python script generate data matrix code

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!
4 REPLIES 4

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.

kekec14
3-Newcomer
(To:dnordin)

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!

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.

kekec14
3-Newcomer
(To:dnordin)

Hello Dan!

 

thank you for the support. Everything works perfectly now. in the attachment is the output of python script. So far I managed to include .dxf to drawing via Insert->Import Drawing/data. Does anyone have idea how to include .dxf file in to part and make extrude future on it.

 

Thank you!

 

regards

 

Announcements


Top Tags