Skip to main content
12-Amethyst
March 19, 2024
Solved

Show file save iteration number in drawing

  • March 19, 2024
  • 5 replies
  • 7294 views

Hello everyone,

 

I'm trying to find a way to show the file save iteration number in a drawing in Creo (Version 4.0 and higher). It will be used for projects without a PDM system to show the exact save iteration, in addition to a revision parameter.

For example for a drawing of a part named DUMMY.PRT.35 I would like to extract the number 35 either directly in the drawing and show it in a note -or- in the part model by placing it into a parameter I can reference in a drawing note.
I haven't found if this is possible somehow. The rel_model_name and model_name parameters do not seem to provide this functionality?

Any help is appreciated!

Best answer by RPN

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 

 

  1. Open the related Drawing
  2. Show the table parameter for the Drawing and the Part
  3. Start a Dummy App just for testing
  4. Save the Drawing - No effect
  5. Connect with the App to Creo
  6. See how to get the full path of a model
  7. Copy the prepared code into the App
  8. Source the code, make it available
  9. Activate the notify function
  10. 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'"
}


 

 

 

5 replies

24-Ruby III
March 20, 2024

Hi,

BASIC INFO -> if you open drawing then Creo opens the latest versions of drawing models.

So how would you like to run your "method"? Please provide simple example.

 

12-Amethyst
March 20, 2024

Hello Martin, 

 

I'm not sure how to explain this in a different way, but this is an example of what it should look like:
Files on disk:

240320_6503_TEST.png

Drawing:

240320_6504_DRW0001.png


Note that this in only meant for cases in which no PDM system is available (in which case I would use e.g. PTC_WM_VERSION and PTC_WM_VERSION:D ). 

 


 

24-Ruby III
March 20, 2024

@Wouter_19472 wrote:

Hello Martin, 

 

I'm not sure how to explain this in a different way, but this is an example of what it should look like:
Files on disk:

240320_6503_TEST.png

Drawing:

240320_6504_DRW0001.png


Note that this in only meant for cases in which no PDM system is available (in which case I would use e.g. PTC_WM_VERSION and PTC_WM_VERSION:D ). 

 


 


Hi,

I understand your picture. However, the data lifecycle needs to be explained.

I would expect this kind of lifecycle:

  • interation numbers of drawing and part start at .1
  • during InWork stage interation numbers change every time you save
  • when project goes into Relased stage then purge action is applied and requested values of interation numbers are included into drawing table

NOTE: Creo enables you to open DUMMY.PRT.35, but Creo does not remember .35 information. Creo only knows that DUMMY.PRT is located in session memory.

14-Alexandrite
March 20, 2024

Hi

The parameter for the iteration is &PTC_WM_ITERATION.

I think that is what you need

pushkarkhanna_0-1710949516715.png

you can also put the revision & version.

 

Pushkar Khanna

21-Topaz II
March 20, 2024

I think the PTC_WM_... parameters are only there if you are using Windchill. The question originally asked was how to do this kind of thing for models not controlled by a PDM system.

23-Emerald III
March 22, 2024

If you have a parameter in your file for revision, that should be all you need to track changes. The iteration will increment with every save and is really meaningless as Creo will always open the latest iteration by default. 

 

Please explain in a little more detail the end objective of putting the file iterations on the drawings. The drawing iteration will be out of date as soon as you do a save with the open iteration.

12-Amethyst
March 29, 2024

The point of having the save iteration number is to know exactly which iteration of a model is used fo a specific drawing revision. So that even if a user (inadvertently) saves the model additional times (with or without changing anything), it will still be clear which iteration the drawing is based on. 

The intended use is somewhat similar to the PDM functionality that allows you to open a drawing with the exact iteration of the model it was saved with, not with an iteration of the model that was created much later. 

12-Amethyst
March 29, 2024

To summarise the findings from all your replies and my testing:

 

It does not seem to be possible to extract the save iteration number directy in Creo without the use of (external) scripting. To me this is not really unexpected, becasue it is not common functionality. 

I will either try writing a script or have the user fill in the drawing field manually only when it's really necessary. 

 

Thank you all for your support! 

1-Visitor
April 2, 2024

I think it is possible with script, and it is not difficult.
I usually use Autohotkey for this kind of purposes. In this case, I would do as follow:
1. Create a parameter named ITERATION and assign a number to it.

2. Update ITERATION to another number.
3. Get the part of the trail file that does the update in step 2.

4. Create a mapkey that runs a certain trail file, eg. t1.txt

5. In autohotkey, create a shortcut with Ctrl S.
This shortcut overloads the Ctrl S you would use to save a model, i.e., when user presses Ctrl S, the model is not saved, but the shortcut is triggered. And here is what the shortcut does:

i) Get current iteration number (by reading Creo Title and use PathSplit)
ii) Generate new iteration number (plus 1 to current number)

iii) Generate the trail file that will update ITERATION parameter to the new iteration number, based on what we got in step 3. Save that trail file as t1.txt

iv) Trigger the mapkey to run t1.txt

And it is done. You can do whatever you want with ITERATION, and that parameter is updated every time an user tries to save the model with Ctrl S.
You can also replace the save icon in the Creo UI with an icon that run the Ctrl S shortcut. It is a little more advanced, but also not difficult at all.

12-Amethyst
April 4, 2024

This is basically what I had in mind, since I have some experience with AutoIt scripting and AutoHotkey. What I don't like about it, is that I have to have additional software constantly running in the background for all users, and that I would have to change the UI for all Creo versions and configurations we use (a lot of them).

RPN18-OpalAnswer
18-Opal
April 3, 2024

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 

 

  1. Open the related Drawing
  2. Show the table parameter for the Drawing and the Part
  3. Start a Dummy App just for testing
  4. Save the Drawing - No effect
  5. Connect with the App to Creo
  6. See how to get the full path of a model
  7. Copy the prepared code into the App
  8. Source the code, make it available
  9. Activate the notify function
  10. 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'"
}


 

 

 

12-Amethyst
April 4, 2024

Wow, this looks really good!
I have never worked with scripting in Creo, so this goes beyond my understanding. I'll try to find some time to look into this soon.

12-Amethyst
May 7, 2024

I found just a little time to look into your solution, but since I have no experience at all with scripting in/for Creo with p-shell, I think it will take me too much time to make it work to make it worth my time. I couldn't even find PTC documentation on it and if it requires a specific license to use.

 

I do want to thank you again for putting in all the effort to find a possible solution and for making the video! I hope someone else can put it to good use.