problem with addOnScriptSave

hey guys,
i have this few lines of code to copy a script to another location after it’s saved.

Code:

import nuke
import shutil

def myfunction():

      currScript = nuke.Root()['name'].value()
       
      backupPath = 'path/to/backup/folder/'

      shutil.copy(currScript, backupPath)


this is the entry in my menu.py

Code:

import myfunction
nuke.addOnScriptSave(myscript.myfunction)


when i overwrite a script that already exists, this works like expected.
but when i try to save the script as a new script, i get an error message. this file doesn’t exist. so nothing is saved and nothing is copied.
i understand that ‘addOnScriptSave’ is executed before the script is saved. so this is an expected error.
i tried ‘nuke.scriptSave()’ before ‘shutil.copy(currScript, backupPath)’, but this gives me another error message: ‘maximum recursion depth exeeded‘.
would be great, if someone can point me to how i get the script saved before the copy command is executed!

thanks a lot,
d

No Responses to “problem with addOnScriptSave”

Post a Comment