I would not use the file based iteration. I would compare the model stamp, if the model stamp has changed bump a parameter.
In the video the part file is open, next
- Open the related Drawing
- Show the table parameter for the Drawing and the Part
- Start a Dummy App just for testing
- Save the Drawing - No effect
- Connect with the App to Creo
- See how to get the full path of a model
- Copy the prepared code into the App
- Source the code, make it available
- Activate the notify function
- Now save, and the model and drawing parameter gets updated
The source code, more comments then code 🙂
# this is the call to activate a callback
#
# ps_notify set MODEL_SAVE_PRE Update_Param_On_Save
#
# After this is called the script Update_Param_On_Save
# will be called just before the final save
proc Update_Param_On_Save {} {
# Get the current model
# and the file extension
set MODEL [ps_model cur]
set EXT [ps_model ext -model $MODEL]
# Now decide what to do
# for PRT or ASM just update the parameter
# for a drawing get the model and update both
switch $EXT {
ASM -
PRT {
Iteration_File_Param_Set $MODEL
}
DRW {
# Assume for test one attached model
set DrwModel [ps_draw list -draw [ps_model cur]]
Iteration_File_Param_Set $DrwModel
Iteration_File_Param_Set $MODEL
# Just show the updated table data
ps_table update -draw $MODEL
}
default {
ps_mess -icon warn "Model $MODEL not supported"
}
}
# It is a PRE Notifier, you can abort
# if return is an integer
# if not 0 save is aborted
# else just continue and save
return 0
}
#
# Just set a model parameter based on the NEXT iteration
#
proc Iteration_File_Param_Set {MODEL} {
set filename [ps_model filename -model $MODEL]
# extension is .35 need 35
# . is 0 so from 1 to end no further checks for demo here
set iteration [string range [file extension $filename] 1 end]
# if you save 20 -you will get 21
incr iteration
ps_param set -model $MODEL ITERATION STRING $iteration
ps_mess -icon warn "Model $MODEL iteration parameter updated to '$iteration'"
}