If | Then | Else Mapkey?
Is it possible to control a mapkey with external parameters? for example If x=1 then Mapkey A else Mapkey B
Yes!
The premise is simple. There is a master mapkey which contains many nested mapkeys. The master mapkey is executed. If x=1 then file “A” is copied into a temp folder. The mapkey executes both the nested mapkeys (the insertion of both file “A” and file “B”. File “B” is not in the temp folder so only file “A” is inserted. Creo does NOT crash when it cannot find file “B” – it just continues to the next command.
Contact me if you would like all required files (CopyTextToClipboard.zip) emailed to you.
Fill out your information below and clik SUBMIT.
NOTE:
The Mapkeys -`mapkey_a_insert_note AND `mapkey_b_insert_note – were previously created.
`Mapkey_A_INSERT_NOTE will insert a note into the top center of the drawing that states: THIS WAS CREATED BY MAPKEY A
`Mapkey_B_INSERT_NOTE will insert a note into the top center of the drawing that states: MAPKEY B WROTE THIS NOTE
The Mapkey – `delete_if_then_temp – was previously created. It deletes all files from C:\ptc\CopyTextToClipboard\temp.
In the examples below, cell_1.txt and cell_2.txt are BOM cell text numerical values (not parameters) that were each saved as an individual text file.
STEPS: Open Creo Drawing | Table Tab | Table Cell (Filter) | Left mouse click on table cell | Properties | Save | Enter full file path including file name | OK
cell_1.txt contains the number 1
cell_2.txt contains the number 2
1. Each batch file was created in notepad (or notepad++) and then tested in Windows first (1A_Solution_Number_1.bat AND 2A_Solution_Number_2.bat). Batch files below:
rem Solution Number 1
rem If x=1 then Mapkey a else Mapkey b
set /p CELL_1=<C:\ptc\CopyTextToClipboard\cell_1.txt
set /p CELL_2=<C:\ptc\CopyTextToClipboard\cell_2.txt
IF %CELL_1% EQU 1 (
copy C:\ptc\CopyTextToClipboard\log_number_1.txt C:\ptc\CopyTextToClipboard\temp\deleteme_log_number_1.txt /Y
) ELSE (
copy C:\ptc\CopyTextToClipboard\log_number_2.txt C:\ptc\CopyTextToClipboard\temp\deleteme_log_number_2.txt /Y
)
rem Solution_Number_2
rem If x=1 Then Mapkey B or
rem If x DoesNot=1 Then Mapkey A
set /p CELL_1=<C:\ptc\CopyTextToClipboard\cell_1.txt
set /p CELL_2=<C:\ptc\CopyTextToClipboard\cell_2.txt
IF %CELL_1% EQU 1 (
goto CELL_2
) ELSE (
copy C:\ptc\CopyTextToClipboard\log_number_1.txt C:\ptc\CopyTextToClipboard\temp\deleteme_log_number_1.txt /Y
)
:CELL_2
copy C:\ptc\CopyTextToClipboard\log_number_2.txt C:\ptc\CopyTextToClipboard\temp\deleteme_log_number_2.txt /Y
2. Open Creo and create a new mapkey.
STEPS: File | Options | Environment | Mapkeys Settings… | New… ( A mapkey was created for each solution in this example.)
They are named (key sequence) almost the same as the batch files.
NOTE: (Once the if/then formula has been determined (Solution 1 or Solution 2) then only one mapkey is required and the values of cell_1.txt and cell_2.txt will determine which mapkey will automatically run.)
Input Key Sequence (!1A_Solution_Number_1), name and description.
Then click on the OS Script tab. The notepad contents for Solution_1 batch file were then copied and pasted into the OS Script window. (Creo will reformat for the mapkey).
Then click OK.
3. Repeat step 2 for second mapkey (!2A_Solution_Number_2).
4. Then save changed mapkeys to config_if_then.pro
5. Open config_if_then.pro in notepad (or notepad++) to edit the newly created mapkeys – !1A_Solution_Number_1, !2A_Solution_Number_2. At the end of the new mapkey(s) add a backslash after the semi colon;\
mapkey(continued) C:\\ptc\\CopyTextToClipboard\\deleteme_log_number_2.txt /Y;\
and then add the next two following nested mapkey lines:
mapkey(continued) %`mapkey_a_insert_note;%`mapkey_b_insert_note;\
mapkey(continued) %`delete_if_then_temp;
The solution(s) above should work on any Creo 2 drawing utilizing the following steps.
1.A. Unzip the contents of CopyTextToClipboard.zip and place into the following folder C:\ptc\CopyTextToClipboard
2.A. Open Creo 2.0 and import the config_if_then.pro. File | Options | Configuration Editor | Import/Export | Import configuration file
2.A. (Continued) Then choose config_if_then.pro | Open | OK | You can now choose to add the import to your current config.pro or not. (If it is not added to your current config.pro – the mapkeys will only be available for the current session).
Mapkey Execution:
Open a drawing in Creo.
Execute mapkey !1A_Solution_Number_1. A note will be created in the top center: THIS WAS CREATED BY MAPKEY A
Execute mapkey !2A_Solution_Number_2. A note will be created in the top center: MAPKEY B WROTE THIS NOTE
DELETE THOSE NOTES FROM THE DRAWING!
Change the value of cell_1.txt to a value >1.
Now Execute mapkey !1A_Solution_Number_1. A note will be created in the top center: MAPKEY B WROTE THIS NOTE
The steps below correspond with the text file – trail_file_from_Creo_session.txt
According to the generated trail file: trail_file_from_Creo_session.txt
1.1 Execute mapkey !1a_solution_number_1. Creo does not record batch file steps into the trail file.
2.1 Creo will execute the nested mapkey (%`mapkey_a_insert_note), and inserts the note into the drawing. Then continues to the next nested mapkey (%`mapkey_b_insert_note).
3.1 Creo will execute the nested mapkey (%`mapkey_b_insert_note), but since the text file (deleteme_log_number_2.txt) was not copied into the temp directory, Creo can NOT find it and continues to the end of master mapkey (!1a_solution_number_1) WITHOUT crashing.
4.1 Execute mapkey !2a_solution_number_2.
5.1 Creo will execute the nested mapkey (%`mapkey_a_insert_note), but since the text file (deleteme_log_number_1.txt) was not copied into the temp directory, Creo can NOT find it and moves to the next nested mapkey (%`mapkey_b_insert_note) WITHOUT crashing.
6.1 Creo will execute the nested mapkey (%`mapkey_b_insert_note), and inserts the note (deleteme_log_number_2.txt) into the drawing. Then continues to the end of the master mapkey !2a_solution_number_2.
BOTH NOTES WERE THEN DELETED FROM THE DRAWING. THESE STEPS WERE DELETED FROM THE TRAIL FILE.
7.1 The value of cell_1.txt was changed from 1 to 2. Execute mapkey !1a_solution_number_1.
8.1 Creo executes the nested mapkey (%`mapkey_a_insert_note), but since the text file (deleteme_log_number_1.txt) was not copied into the temp directory, Creo can NOT find it and continues to the next nested mapkey (%`mapkey_b_insert_note) WITHOUT crashing.
9.1 Creo executes the nested mapkey (%`mapkey_b_insert_note), and inserts the note (deleteme_log_number_2.txt) into the drawing. Then continues to the end of the master mapkey !1a_solution_number_1.