Skip to content

Instantly share code, notes, and snippets.

@BenMcEwan
Last active December 6, 2019 00:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenMcEwan/c8c9be01085eb0c8ae779dedc8e9785c to your computer and use it in GitHub Desktop.
Save BenMcEwan/c8c9be01085eb0c8ae779dedc8e9785c to your computer and use it in GitHub Desktop.
# --------------------------------------------------------------
# NetCopy.py
# Version: 2.0.0
# Last Updated: January 11th, 2018
# --------------------------------------------------------------
# --------------------------------------------------------------
# USAGE:
#
# Define temp directory on the network below.
# Ctrl+Shift+C will "copy" to the network
# Ctrl+Shift+V will bring up "paste" window, that lets you choose a username & script to import
# --------------------------------------------------------------
import nuke
import getpass
import os
def netCopyV2():
# Define temp directory on the network.
dir = '/data/studio/tools/nuke/netCopy/'
usr = getpass.getuser()
fPath = dir + usr
# Check to see if the directory exists, and if not, create it.
if not os.path.isdir(fPath):
os.makedirs(fPath)
txt = nuke.getInput('Snippet Name', '')
# Export selected nodes to a nuke script labelled with the user's username.
fileName = os.path.join(os.path.normpath(fPath), txt)
if os.path.exists(fileName):
if nuke.ask('Snippet already exists, would you like to overwrite?'):
nuke.nodeCopy(fileName)
else:
nuke.nodeCopy(fileName)
def netPasteV2():
# Define temp directory on the network.
filePath = '/data/studio/tools/nuke/netCopy/'
fileList = nuke.getFileNameList(filePath)
# Opens dialog box with pulldown choice of username.
result = nuke.choice("NetPaste", "Pick Username", fileList)
# If nothing is selected, do nothing.
if result is None:
return
# Otherwise, select username and move to next step
choice = fileList[result]
# Define user file directory
filePath2 = (os.path.join(filePath, choice))
fileList2 = nuke.getFileNameList(filePath2)
# Opens dialog box with pulldown choice.
result2 = nuke.choice("NetPaste", "Pick Snippet", fileList2)
# If nothing is selected, do nothing.
if result is None:
return
# Otherwise, import script of selected username.
choice2 = fileList2[result2]
nuke.nodePaste(os.path.join(filePath2, choice2))
# Add the following to menu.py
import netCopyV2
nuke.menu('Nuke').addCommand( 'Edit/NetCopy', 'netCopyV2.netCopyV2()', 'ctrl+shift+c')
nuke.menu('Nuke').addCommand( 'Edit/NetPaste', 'netCopyV2.netPasteV2()', 'ctrl+shift+v')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment