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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Repeat code for trail files/mapkey


Repeat code for trail files/mapkey

Does anyone know the code to repeat block for doing specific action in trail file/mapkey?


I don't think there is any sort of looping functionality in trail files or map keys, based upon the fact that there is none for relations. No "for", "do...while", or "repeat...until" constructs. The execution of commands is analogous to a tape running through a reader. It proceeds straight through the code and your only logical branching is done with "if" statements.


In a-synchronous mode you can easily write your own control structure und use while, for or what ever control structure. This example will open files, give by it full path and generate a STEP or IGES output. With Tcl it is very easy to deal with strings, this makes it easy to manipulate mapkey's.


# Main Action, Hardcoded here
# Input where ever you get the full path from
proc MK_Action {} {

        set files [list]
        lappend files c:/CreoTickle/work/models/blower.asm
        lappend files c:/CreoTickle/work/models/frame.prt
        lappend files c:/CreoTickle/work/models/nut.prt
        lappend files c:/CreoTickle/work/models/piston_pin.prt

        foreach file $files        {

                # Run the Mapkey
                MK_Change_Dir        [file dirname $file]
                # Or write on the fly a config file
                # MK_Change_Dir_By_Config_File [file dirname $file]
                MK_File_Open        [file tail $file]
                MK_File_Save_As        STEP



The complete code can be found in Mapkeys - Use Mapkey in Asynchronous mode

Using this is helpful for beginners, but at the end you don't have really a function feedback (Return code), and the map key's may change from version to version. But if you have a mapkey library it's for sure very easy to program. Generate all the mapkey can be time consuming as well.

You can actually do this easily in OpenSource CREOSON (depending on the language you want to use)...


Trail Files are a bit more sensitive ... but Mapkeys seem to work well.


  1. Just record the mapkey
  2. Save to
  3. Open the
  4. Copy the mapkey body out and create a variable/reference in your automation script. (e.g. myMapKey)
  5. Replace the current selection reference (e.g. filename) with something generic like "FILENAME"
  6. Loop through your files... replacing "FILENAME" in your "myMapKey" variable with your current file and execute the modified mapkey on with each iteration...
  7. Smile 🙂

This depends on the language you want to use... but with CREOSON you have many options due to the generic JSON interface.    Javascript and Python are good examples of how this is being used currently...


Hope that helps!





Hi Folks, I have created the web application: 

Repeatable Mapkey Generator | How to loop Creo Mapkey - try to check the video tutorials first:

Best Regards,
Vladimir Palffy
If you enjoy my content, please consider supporting what I do: Buy a Coffee for 4KSide - or DONATE by WHY SHOULD YOU DONATE TO 4K SIDE? More donation = more money More money allows me to buy more coffee More coffee makes me create more Creo ...