Exporting animated sequences of images out of Creo Parametric
Sometimes I like to animate flexible things that can't be done with kinematics (e.g. springs), or setup complicated simulations depending on a time parameter. Setup a relation such as "value = value + 1", and the model will update with every regeneration. Then save an image file after each update, and create a GIF (or other video file) with the results. This is pretty easy to do if you only have a small number of frames, but for a large number, the lack of automation will become a problem.
I had initially thought I could automate this with a mapkey, but I hit a brick wall trying to save an image with a unique filename each time. (I got as far as using relations to compose a properly formatted filename, getting a mapkey to copy the value, and paste into the filename field when saving the image... but turns out mapkeys are actually not capable of copy/paste operations on playback.) I wound up creating a mapkey that calls a windows batch file, which writes a new customized mapkey for the desired animation, spelling out all the regenerations and saves. (The *.bat file uses a loop; the custom mapkey does not, it's like a long player piano scroll, with a new filename specified for each loop.)
This was far a more complicated effort than the initial simulation I was working on! Since it was done on my own time and not at the direction of my employer, and isn't even related to our industry, I've decided to release the utility with a General Public License. I've tested it with Creo Parametric 2.0 & 4.0, and it works equivalently on both platforms. So, I doubt there will be issues with Creo 3.0. Haven't been able to test with Creo 5.0, as our license server does not support it. Like any mapkey, these are very likely to break with new versions of Creo, if the GUI they manipulate has changed. But hopefully, will be easy to fix in the future when this happens. The mapkeys are broken up into subroutines that perform just one function each, to make isolating and fixing problems easier. The code is full of comments with helpful hints and instructions on how to make updates in the future.
The 3 files needed to make it work are pasted below, but you may wish to check my github for any updates:
https://github.com/wackyneighbor/Image_Sequence_Animation_Exporter_for_Creo_Parametric
Files needed:
- animation_relations_sample.txt - Paste the contents of this file into the model you wish to animate, and follow included notes for creating needed model parameters
- animation_start_mapkey.pro - This file includes the code for the "mapkey" used to start the process. Paste the contents of this into your "config.pro" settings file if you'd like this to be always available. Otherwise, save the file somewhere convenient, such as your Creo "working directory", and import whenever needed. (File / Options / Configuration Editor / Import configuration file)
- animation_sequence_mapkey_generator.bat - This generates a customized mapkey for the desired animation. It MUST be saved in your Creo "working directory".
To use:
- Set up model to be animated, using relations from sample file, and ensure the initial mapkeys have been imported into your current session.
- Type "configanim".
- Follow the instructions in the console window that appears. You will be prompted for the number of regenerations to use between frames, the name of the saved view orientation to reset after regeneration (optional; only needed for perspective views), the number of frames to save, the height & width in pixels for the exported images, the filename prefix to use for the images, whether to use default of *.png image format, or switch to *.tif (Creo 2.0 doesn't support *.png).
- Image files will be saved to your Creo "working directory".
Alternatively:
- To skip the configuration dialog and begin exporting a sequence using the same settings last configured, type "cycleanim".
- Import the "animation_sequence_mapkey.pro" file that was left in your working directory to use a "cycleanim" created in a previous session.
To avoid "letterboxed" output, and ensure on-screen annotations appear as WYSIWYG:
Although you specify the precise dimensions of your output images, Creo will letterbox the results to match the aspect ratio of your current model viewport window. Additionally, any on-screen annotations that are shown will have proportions relative to your current model viewport, rather than the size of your output images. The window size may shift along with changes to your computer's monitor resolution (such as if you shut the lid of a laptop).
To prevent these issues and ensure you get consistent output, it is advisable to lock the interactive viewport window to be the same dimensions you will use for image export. You may do this with the hidden config.pro setting "force_base_size 1280 720" (where 1280 and 720 are the desired width and height in pixels, respectively). Note that you must add this line to your config.pro before launching Creo. Adding this config setting to an active session will have no effect, although you may change the current height and width settings at any time during a session where the setting was activated. This is not a convenient setting to have in effect at any time when you are not exporting animations, so be sure to remove the line from your config.pro afterwards. (Or comment out by preceding with "!")
Desired enhancements:
- A convenient mechanism to cancel a recording in progress.
- Include system for moving light sources between frames, such as the sun going across the sky. This could be accomplished by analyzing the location of two datum points, and writing the coordinates to a file outside of Creo. Use *.bat file to parse this file for the coordinates, and create a customized *.dlg file specifying these locations as the source & aim point for a distant light. Import the light to the current scene before saving image.
- Use photo-realistic rendering for each frame, rather than just saving an image.
animation_relations_sample.txt:
/* Creo Parametric relations for animating via regeneration loops /* by Darren Cokin v1.0 November 2018 General Public License /* /* Replace <animated_parameter> with the parameter or dimension you would like /* to vary. Replace <starting_value> with a parameter, or just enter a number. /* Replace <animation_increment> with a parameter, or just enter a non-zero /* number. /* /* Please create the following standard animation control parameters in the /* model, with indicated types: /* animate_with_every_regen = yes no /* animation_current_frame = integer /* regenerations_needed = integer /* regeneration_counter = integer /* dynamic_text = string /* /* If you would like your model to include a control panel, with flat to screen /* text overlaid on the model where parameters can be displayed and varied, /* you may also wish it to disappear when it's time to save an image. Create /* as an annotation feature, and edit model's program (Tools / Model Intent / /* Program) to include this statement before the feature's "ADD FEATURE" /* statement: /* if animate_with_every_regen == no | (animate_with_every_regen == yes & \ /* regeneration_counter != regenerations_needed) /* And also include an "endif" statement after the the feature's "END ADD" /* statement. /* /* Begin animation control algorithm: /* If animation is not active, reset animated parameter to starting value, /* reset frame count, reset regeneration count, and reset dynamic text. if animate_with_every_regen == no <animated_parameter> = <starting_value> animation_current_frame = 1 regeneration_counter = 1 dynamic_text = "SIMULATION IS NOT RUNNING" else /* Check if this is the second to last regeneration cycle. This is when the /* model is fully regenerated, and we save the image for the animation /* frame. /* Increment regeneration count, and update dynamic text. if regeneration_counter == regenerations_needed - 1 regeneration_counter = regeneration_counter + 1 dynamic_text = "SIMULATION FRAME " + itos(animation_current_frame) + \ + " READY. REGENERATE " + itos(regenerations_needed) + \ "X TO CONTINUE AFTER SCREEN CAPTURED." else /* Check if this is the last regeneration cycle. If so, increment /* animated parameter, increment frame counter, reset regeneration /* counter, and update dynamic text. if regeneration_counter == regenerations_needed regeneration_counter = 1 animation_current_frame = animation_current_frame + 1 <animated_parameter> = <animated_parameter> + <animation_increment> /* if user had only requested one regeneration cycle, it will go /* to this part of loop every cycle. Use alternate dynamic text /* in that case. if regenerations_needed == 1 dynamic_text = "SIMULATION FRAME " + \ itos(animation_current_frame) + \ " READY. REGENERATE TO CONTINUE AFTER SCREEN CAPTURED." else /* update dynamic text for usual case with multiple regens dynamic_text = "SIMULATION FRAME " + itos(\ animation_current_frame) + " IN WORK. REGENERATE " + \ itos(regenerations_needed - 1) + "X MORE." endif else /* When in any regen cycle that isn't the last or second to last, /* just increment the regeneration counter and dynamic text. regeneration_counter = regeneration_counter + 1 dynamic_text = "SIMULATION FRAME " + itos(\ animation_current_frame) + " IN WORK. REGENERATE " + \ itos(regenerations_needed - regeneration_counter) + "X MORE." endif endif endif
animation_start_mapkey.pro:
! Welcome to the Image Sequence Animation Mapkey Generator for Creo Parametric ! by Darren Cokin v1.0 November 2018 General Public License ! ! Mapkeys: ! configanim = configure a new animation sequence, and start it running ! cycleanim = restart animation using last configuration ! importmapkey = reload last configuration created in previous session ! into current session, so 'cycleanim' is available ! This subroutine imports the newly created animation_sequence_mapkey.pro file ! into the current Creo Parmametric session. mapkey importmapkey @MAPKEY_LABELimports *.pro file with mapkey to save entire animation;\ mapkey(continued) ~ Close `main_dlg_cur` `appl_casc`;~ Command `ProCmdRibbonOptionsDlg` ;\ mapkey(continued) ~ Trail `UI Desktop` `UI Desktop` `PREVIEW_POPUP_TIMER` \ mapkey(continued) `main_dlg_w1:PHTLeft.AssyTree:<NULL>`;\ mapkey(continued) ~ Activate `ribbon_options_dialog` `ConfigLayout.Open`;\ mapkey(continued) ~ Trail `UI Desktop` `UI Desktop` `DLG_PREVIEW_POST` `file_open`;\ mapkey(continued) ~ Activate `file_open` `Current Dir`;\ mapkey(continued) ~ Select `file_open` `Ph_list.Filelist` 1 \ mapkey(continued) `animation_sequence_mapkey.pro`;\ mapkey(continued) ~ Trail `UI Desktop` `UI Desktop` `PREVIEW_POPUP_TIMER` \ mapkey(continued) `file_open:Ph_list.Filelist:<NULL>`;\ mapkey(continued) ~ Command `ProFileSelPushOpen_Standard@context_dlg_open_cmd` ;\ mapkey(continued) ~ Activate `ribbon_options_dialog` `OkPshBtn`;\ mapkey(continued) ~ FocusIn `UITools Msg Dialog Future` `no`;\ mapkey(continued) ~ Activate `UITools Msg Dialog Future` `no`; ! This mapkey launches the "animation_sequence_mapkey_generator.bat" utility, ! which will prompt the user for various inputs, and then write a custom ! animation_sequence_mapkey.pro file. This mapkey then continues to call a ! subroutine to import that file into the current session, and then starts ! running the animation sequence via the mapkey in that file. mapkey configanim @MAPKEY_LABELconfigures new animation and starts it;\ mapkey(continued) @SYSTEManimation_sequence_mapkey_generator.bat;\ mapkey(continued) %importmapkey;%cycleanim;
animation_sequence_mapkey_generator.bat:
see comments; hit length limit in this post

