Custom Save_As script with date prefix

Hi Guys,

I’ve been using a custom Save_As button for a few years as part of my own file management.

What it does is take what ever Rhino Doc I have open and add/update the file name with a YYMMDD_ prefix and save it to my desktop.

If a Grasshopper Doc is open at same time it gets the same filename/prefix/save to Desktop treatment.

Up until today the Desktop folder was hard coded into the script, but some looking around the GH API docs last night had me find the Grasshopper.Folders.Desktop method - which allows easy finding of the current users desk top folder and makes this code now very portable.

Here it is for anyone else want the same function:

#Saves open rhino and grasshopper to Desktop with YYMMDD_ prefix

import rhinoscriptsyntax as rs
import System
import time

import Rhino
import Grasshopper

GH = Rhino.RhinoApp.GetPlugInObject("Grasshopper")

dateandtimenow = time.strftime("%Y%m%d")
save_date = dateandtimenow[2:]

desktop_path = Grasshopper.Folders.Desktop

current_name = rs.DocumentName()

if ('_') in current_name:
	current_name = current_name.split('_',1)[1]

rhino_save_file_name = chr(34) + desktop_path + '\\'+ save_date + '_' + current_name + chr(34)

cmd = '-_SaveAs ' + rhino_save_file_name 

rs.Command(cmd, True)

if GH.IsEditorLoaded():
	import clr
	import Grasshopper 
	gh_save_file_name = desktop_path + '\\' + save_date + '_' + current_name.split('.')[0] + '.gh'
	Grasshopper.Plugin.GH_RhinoScriptInterface.SaveDocumentAs(GH, gh_save_file_name)

1 Like