When Creo launches a script, the "Current Working Directory" is NOT your Creo session directory. It is often C:\Program Files\PTC\Creo X.0\bin\.
Fix: Always use absolute paths in your scripts (e.g., C:\Logs\ instead of Logs\). Or, at the top of your batch script, add cd /d "%~dp1" to change to the directory of the file Creo passed.
First, record a Mapkey that exports a BOM (Table > Save As > CSV). Then modify it:
mapkey bom_export @MAPKEY_NAMEExport BOM to DB;\
~ Command `ProCmdTblSaveAs` ;\
~ Select `file_saveas` `type_option` 1 `csv`;\
~ Path `file_saveas` `FileName_Input_Browse` `C:\temp\bom_temp.csv`;\
~ Command `ProCmdFileSave` ;\
~ Command `ProCmdUtilSystem` `system("python C:\creo_scripts\export_bom_to_db.py C:\temp\bom_temp.csv")`;\
~ Command `ProCmdFileEraseNotDisp` ;
Now pressing your Mapkey exports the BOM, processes it with Python, and sends it to your database.
For complex data processing (CSV formatting, database uploads), Python is superior.
This is the simplest form of OS scripting.
Goal: Open the Windows Calculator when pressing F3. creo mapkey os script example
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;
A Mapkey records your keystrokes, menu picks, and mouse clicks within the Creo interface. When you press a shortcut (e.g., F2 or Ctrl+D), Creo replays those commands instantly.
Why add an OS Script? Native Mapkeys cannot:
By calling an OS script, a Mapkey bridges the gap between Creo’s internal API and your Windows/Linux file system.
@echo off set PART_NUMBER=%1 set REV=%2 set DATE=%DATE:/=-% set SOURCE_DIR=C:\CREO_EXPORTS set DEST_DIR=\\SERVER\MANUFACTURING\%PART_NUMBER%REM Create destination mkdir "%DEST_DIR%" 2>nul When Creo launches a script, the "Current Working
REM Rename and move STEP if exist "%SOURCE_DIR%\current.step" ( copy "%SOURCE_DIR%\current.step" "%DEST_DIR%%PART_NUMBER%R%REV%%DATE%.step" )
REM Rename and move PDF if exist "%SOURCE_DIR%\current.pdf" ( copy "%SOURCE_DIR%\current.pdf" "%DEST_DIR%%PART_NUMBER%R%REV%%DATE%.pdf" )
REM Log it echo %DATE% %TIME% - Released %PART_NUMBER% Rev %REV% >> \SERVER\LOGS\release.log exit /b 0
Creo Mapkeys cannot natively pass Creo parameters (like &model_name) directly inline. However, you can use a two-step workaround: Now pressing your Mapkey exports the BOM, processes
Method: Write to a temporary file
Inside your Mapkey, use ~ Command ProCmdUtilSystem system("echo %CURRENT_MODEL% > C:\temp\var.txt");
Then your OS script reads that file.
Better: Use Creo’s trail file or relations to print parameters.
Example: Create a relation that writes a parameter to a text file:
RELATION: OUTPUT_TEXT = "MODEL=" + rel_model_name()
WRITE(OUTPUT_TEXT, "C:/temp/model_name.txt")
Then your OS script parses model_name.txt.