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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

How to loop a mapkey?

RG_10671499
12-Amethyst

How to loop a mapkey?

I have created a mapkey to open a .prt and import to .stp(refer config2.pro). I succeed on that one. But I also have several .prts to convert to .stp. so I copy the mapkey, pasted various instances and replaced the .prt names(config3). but it didnt work. 

RG_10671499_0-1686061816551.png

later i found some tools from here Repeatable Mapkey Generator – 4K Side and that one works.

how did that work mine gives error?

 

ACCEPTED SOLUTION

Accepted Solutions

I also created a simple python script to automate the process.

def replace_text(input_file, input0_file, list_file, output_file):
    with open(input_file, 'r') as f_input, open(input0_file, 'r') as f_input0, open(list_file, 'r') as f_list, open(output_file, 'w') as f_output:
        input_text = f_input.read()
        input0_text = f_input0.read()
        list_lines = f_list.readlines()

        modified_text = input0_text.replace('XXXX.stp', list_lines[0].strip())
        f_output.write(modified_text)

        for line in list_lines[1:]:
            modified_text = input_text.replace('XXXX.stp', line.strip())
            f_output.write(modified_text)

    print(f"Replacements completed. Modified text saved to {output_file}.")

# Replace the file paths with your actual file names
replace_text('input.txt', 'input0.txt', 'list.txt', 'output.txt')

The input0.txt has the 1st instance of the fresh mapkey, i think this is larger when compared to next instances. so i made it special.

The input.txt is the next instances of the particular list. ( so you have to record the mapkey for 2 or 3 creo files)

The list.txt has all the information about what the files are to be affected by this mapkey.

Both input.txt and input0.txt should have same replaceable instance. I used XXXX.stp. Also they both should have an empty line at end of the file, so that next instance will copy to the next line. list.txt shouldn't have any empty lines.

 

The output.txt consists the mapkey code from the second line. Open this and delete the last \ in order to end the mapkey. Now you can copy and paste to the previously created mapkey.

Enjoy.

I attach some files this worked for me.

Let me know if you have any comments.

Thanks.

RG_10671499_0-1686067530515.png

 

RG_10671499_1-1686067622794.png

 

View solution in original post

6 REPLIES 6

LOL. I figured it out. The problem is, in order to loop/mapkey(continued) the there should be a ;\ I used ; only.

; only used for the end of the mapkey. Now I can loop.

I also created a simple python script to automate the process.

def replace_text(input_file, input0_file, list_file, output_file):
    with open(input_file, 'r') as f_input, open(input0_file, 'r') as f_input0, open(list_file, 'r') as f_list, open(output_file, 'w') as f_output:
        input_text = f_input.read()
        input0_text = f_input0.read()
        list_lines = f_list.readlines()

        modified_text = input0_text.replace('XXXX.stp', list_lines[0].strip())
        f_output.write(modified_text)

        for line in list_lines[1:]:
            modified_text = input_text.replace('XXXX.stp', line.strip())
            f_output.write(modified_text)

    print(f"Replacements completed. Modified text saved to {output_file}.")

# Replace the file paths with your actual file names
replace_text('input.txt', 'input0.txt', 'list.txt', 'output.txt')

The input0.txt has the 1st instance of the fresh mapkey, i think this is larger when compared to next instances. so i made it special.

The input.txt is the next instances of the particular list. ( so you have to record the mapkey for 2 or 3 creo files)

The list.txt has all the information about what the files are to be affected by this mapkey.

Both input.txt and input0.txt should have same replaceable instance. I used XXXX.stp. Also they both should have an empty line at end of the file, so that next instance will copy to the next line. list.txt shouldn't have any empty lines.

 

The output.txt consists the mapkey code from the second line. Open this and delete the last \ in order to end the mapkey. Now you can copy and paste to the previously created mapkey.

Enjoy.

I attach some files this worked for me.

Let me know if you have any comments.

Thanks.

RG_10671499_0-1686067530515.png

 

RG_10671499_1-1686067622794.png

 

Hi,

just additional information.

https://www.ptc.com/en/support/article/CS114528 tells us that the length of mapkey code had a limit in the past.


Martin Hanák

257004 lines 😮

i think that itself too much. 

You can get around this by having a mapkey that acts as a subroutine and you call that subroutine mapkey from your main mapkey.

 

ie:

mapkey abc @MAPKEY_NAMEMaykey that calls another;@MAPKEY_LABELABC;\
mapkey(continued) %def;\
mapkey(continued) ~ Input `file_open` `Inputname` `DRAWING.DRW`;\
mapkey(continued) ~ Update `file_open` `Inputname` `DRAWING.DRW`;\


mapkey def @MAPKEY_LABELDEF;\
mapkey(continued) ~ Command `ProCmdModelOpen` ;\
mapkey(continued) ~ Trail `UI Desktop` `UI Desktop` `DLG_PREVIEW_POST` `file_open`;

 

By repeating lines of code that don't change, this can significantly shorten up the mapkey

I even made a .exe utility. If anyone needs it then ping me 🙂

Announcements
NEW Creo+ Topics: Real-time Collaboration


Top Tags