In a Creo configuration file (config.pro), an OS script mapkey looks different than a standard UI mapkey.
Standard Mapkey syntax:
mapkey $F1 ~ Close `main_dlg_cur` `main_dlg_cur`;
OS Script Mapkey syntax:
mapkey $F2 @SYSTEM command_to_run;
Key Components:
Create a mapkey that:
This demonstrates basic OS commands: model selection, feature creation, parameter setting, and save. creo mapkey os script example
The Problem: You have a drawing (.drw). You want to export a PDF, move it to a specific \Release folder, and append today’s date—all with one click.
Step 1: The Batch Script (export_pdf.bat)
Save this to C:\Creo_Scripts\export_pdf.bat:
@echo off set source_file=%1 set source_path=%~dp1 set source_name=%~n1 set target_folder=%source_path%Release:: Check if Release folder exists, if not, create it if not exist "%target_folder%" mkdir "%target_folder%"
:: Get today's date (Format: YYYY-MM-DD) for /f "tokens=1-3 delims=/ " %%a in ('date /t') do set curdate=%%c-%%a-%%b
:: Copy the PDF (assuming Creo saved it as PDF in source folder) copy "%source_path%%source_name%.pdf" "%target_folder%%source_name%_%curdate%.pdf" In a Creo configuration file ( config
echo PDF Exported to %target_folder% >> C:\Creo_Logs\export_log.txt
Step 2: The Mapkey Definition
Record a Mapkey named PDFR (PDF Release):
Result: Press PDFR. Creo exports the PDF, then calls the batch file to move + rename it.
You cannot run OS_Script delete_temp_files.bat and immediately OS_Script erase current.prt in the same Mapkey. The first script might still be running when the second starts.
Fix: Use !OS_Script (sequential) or merge your logic into a single master script. Key Components:
Cause: The executable is not in the Windows PATH variable, or there is a typo.
Fix: Use Absolute Paths (e.g., C:\Windows\System32\calc.exe) instead of just calc.exe.
mapkey $F12 @MAPKEY_NAMERelease to MFG;\
~ Command `ProCmdModelSaveAs` ;\
~ Select `file_saveas` `type_option` 1 `STEP`;\
~ Open `file_saveas` `ph_list.Filelist`; \
~ Select `file_saveas` `ph_list.Filelist` 1 `C:\CREO_EXPORTS\current.step`;\
~ Command `ProCmdFileSave` ;\
~ Command `ProCmdPrint` ;\
~ Select `print_dlg` `pdf_export_btn` 1 ;\
~ Activate `print_dlg` `OK` ;\
~ Delay 1 ;\
~ Command `ProCmdUtilSystem` `system("C:\scripts\release_to_manufacturing.bat &model_name &pro_mp_revision")`;\
~ Command `ProCmdFileEraseNotDisp` ;
Note: &model_name and &pro_mp_revision are Creo system parameters. The Mapkey passes them as arguments to the batch file.
This is the simplest form of OS scripting.
Goal: Open the Windows Calculator when pressing F3.
mapkey $F3 @SYSTEM calc.exe;
Goal: Open a specific "Notes.txt" file located on your desktop for quick engineering notes.
mapkey $F4 @SYSTEM notepad.exe C:\Users\YourName\Desktop\Notes.txt;