Keyboard shortcut for 'Save Project As...'

Hi there,

I was wondering if there is any way of assigning a keyboard shortcut to the ‘Save Project As…’ function inside in Silhouette? I use it a lot to version up my scripts, renaming the project file from something like roto_v001 to roto_v002.

What would be even better is a any way to automatically version up a project using a menu item or keyboard shortcut. Something similar to the ‘Save New Comp Version’ function in Nuke.

Any help for either of these requests would be much appreciated.

Thanks,
Josh

Yes, this is possible, using the project.save(path) function. The code below can be bound to a key. increment_project_version() needs to be implemented but it should be straightforward.

from fx import *
import os

# get the active project
p = activeProject()
path = p.path
# remove the ending project.sfx from the path
path = os.path.split(path)[0]
# increment the version in the path - please implement
path = increment_project_version(path)
p.save(path)

BTW - the os.path.split() line is only needed if the path ends with “project.sfx”. It might not on Mac.

Hi there Paul,

Thank you so much for the reply. Unfortunately I am some what of a beginner at python and coding in general, so I might need a little more guidance to implement this properly.

I first started by copy and pasting the code you sent into the Script Editor window within Silhouette and executing it there, but was getting this error in the console:

NameError: name 'increment_project_version' is not defined

I had a go at defining it all, and assigning ‘Crlt+Shift+s’ to the command using the fx.bind function so all together I had this:

import fx
from fx import *
import os

def increment_project_version():

	# get the active project
	p = activeProject()
	path = p.path
	# remove the ending project.sfx from the path
	path = os.path.split(path)[0]
	# increment the version in the path - please implement
	path = increment_project_version(path)
	p.save(path)


fx.bind("Ctrl+Shift+s", increment_project_version)

I am now getting this error message:

TypeError: increment_project_version() takes 0 positional arguments but 1 was given

Obviously before you said that increment_project_version() needs to be implemented, sadly I am unsure what you mean by this.

Apologies if the solution is a straightforward and easy one. Again I am very new and inexperienced to all this so any help would be incredibly appreciated.

Thanks,
Josh

Ok, sorry for the confusion. You do need a function to bind to the key, and a separate function to actually increment the version number. I wasn’t absolutely sure of your numbering scheme so I left that as an exercise. Let me work on a more complete example for you.

Try this:

from fx import *
import os
import re

# this function expects a path with version at end like:
# /path/to/ProjectName.#.sfx
# if there is no version # at end, '1' will be added
def increment_path_version(path):
	match = re.search(r'(\d+)\.\w+$', path)
	if match:
		span = match.span(1)
		value = match.group(1)
		value = int(value) + 1
		root = path[:span[0]]
		end = path[span[1]:]
		path = root + str(value) + end
	else:
		# set the version # to 1
		file, ext = os.path.splitext(path)
		path = file + ".1" + ext

	return path

def increment_project_version():
	# get the active project
	p = activeProject()
	path = p.path
	# remove the ending project.sfx from the path
	if os.path.split(path)[1] == 'project.sfx':
		path = os.path.split(path)[0]
	# increment the version in the path - please implement
	path = increment_path_version(path)
	p.save(path)

fx.bind("Ctrl+Shift+s", increment_project_version)

Hey Paul,

It looks like isn’t quite working properly unfortunately.

The part that adds ‘1’ if there is no version # seems to work but is adding “.sfx” to the end, and when pressing Ctrl+Shift+s more than once it just adds “.1.sfx” to the end instead of incrementing the number up.

If I save a project without a version # like this:

And run the code by pressing Ctrl+Shift+s, it names it “test_roto.1.sfx.sfx” like this:
image

If I then press Ctrl+Shift+s again, it continues to add “.1.sfx” to the end like this:
image

Obviously the part of the code that says remove the ending project.sfx from the path is not working correctly. Is there something I need to change to make it fit with the file path my projects are saved to?

If I do put a version # when saving a project like this:

And then press Ctrl+Shift+s, it does successfully version the number up but is still adding an extra “.sfx”:
image

At work we use Linux, and the naming convention _v001, _v002, _v003, and so on to version our projects so would it be possible to have it use that format rather than just .1?

It is worth noting that /net/home/jgreen/Desktop/Silhouette_test_scripts is not the location I would normally be saving my projects, this is just for testing purposes. The file path we would be saving the actual Silhouette projects to would look more like: /job/show/film/abc000/abc000_0123/work/jgreen/silhouette/scripts, however this does slightly change from show to show.

Hey all,

I’ve been working on this with Josh and we have a working setup that increments the version number now however we’re running into a weird issue.

It appears the project.save() method, doesn’t actually seem to save modifications.
For example, if we have a v001 script, and do some changes, we see the * appear in the project name, signifying we’ve made modifications that haven’t been saved. If we then run our script, the version number will update, and a new project directory will be created as expected, but the modifications aren’t saved. We’ll get a v002*.
Even if I simply run:

import fx

project = fx.activeProject()
project.save()

It doesn’t save the modifications, which is something I’d expect it to do.
Any advice on getting this functionality to work?

Thanks,
Corin

I fixed the bug related to this [SI-1469] in the 2022.5.2 maint release, which should release soon.