Skip to content

Instantly share code, notes, and snippets.

@fredrikaverpil
fredrikaverpil / sql-backup.bat
Last active August 29, 2015 13:56
mySQL BAT backup script
REM Export all data from this database
cd C:\Program Files\MySQL\MySQL Server 5.6\bin
REM To export to file (structure only)
mysqldump --no-data [DATABASENAME] -h localhost -u [USER] -p[PASSWORD] > C:\databackup\database_ddl_backup.sql
mysqldump --no-create-info --no-create-db [DATABASENAME] -h localhost -u [USER] -p[PASSWORD] > C:\databackup\database_data.sql
@fredrikaverpil
fredrikaverpil / nuke_traverse_backwards.py
Created March 25, 2014 12:58
Traverse backwards folderpath to find a folder #nuke
def traverseBackwardsAndFindFolder( startPath, searchForFolder ):
# Usage example: traverseBackwardsAndFindFolder( nuke.root().name(), 'render' )
returnPath = ''
for i in range(len(startPath.split('/'))):
startPath = startPath[:startPath.rfind('/')]
# Check if it exists
if (os.path.isdir(startPath + '/' + searchForFolder)):
returnPath = startPath + '/' + searchForFolder
@fredrikaverpil
fredrikaverpil / nuke_environment.py
Last active August 29, 2015 13:57
Get environment settings #nuke
# List Nuke's environment settings
print( nuke.root() )
# Nuke script's filename
print( os.path.basename( nuke.root().name() ) )
# Nuke script's directory
print( os.path.dirname( nuke.root().name() ) )
@fredrikaverpil
fredrikaverpil / get_subdirs.py
Created March 25, 2014 13:04
Get subdirectory of directory #python
def getSubdirs( directory ):
for item in os.listdir( directory ):
# print path to all subdirectories first.
if os.path.isdir( os.path.join( directory, item ) ):
print item
@fredrikaverpil
fredrikaverpil / find_dir.py
Created March 25, 2014 13:05
Find directory based on search string #python
# This searches for a sequence of characters
import os
def checkForDir(searchDirs, partialOrFullDirNameToFind):
for searchDir in searchDirs:
for directory in os.listdir(searchDir):
if partialOrFullDirNameToFind in directory.lower():
foundDirectories.append(searchDir + directory)
return str(foundDirectories[len(foundDirectories)-1])
@fredrikaverpil
fredrikaverpil / walk_search_replace.py
Created March 25, 2014 13:07
Walk folder and search and replace in files #python
import os
startDirectory = "c:/temp/"
searchString = "maya2012"
replacement = """multiline
string"""
for dname, dirs, files in os.walk(startDirectory):
for fname in files:
if ".ma" in fname:
fpath = os.path.join(dname, fname)
@fredrikaverpil
fredrikaverpil / get_last_modified_date.py
Created March 25, 2014 13:07
Get "last modified" date of file #python
import os, time
def getYYMMDD(filepath):
statbuf = os.stat(filepath)
date = time.localtime((statbuf.st_mtime))
# Debug
#print str(date)
# Extract out the year, month and day from the date
@fredrikaverpil
fredrikaverpil / disable_unselected_write_nodes.py
Created March 25, 2014 13:10
Disable unselected Write nodes #nuke
def disableUnselectedWriteNodes():
selectedNodes = nuke.selectedNodes() # Get all selected nodes
allWriteNodes = nuke.allNodes('Write') # Get all write nodes
for node in allWriteNodes:
nuke.toNode(node.name()).knob('disable').setValue(True)
for node in selectedNodes:
nuke.toNode(node.name()).knob('disable').setValue(False)
@fredrikaverpil
fredrikaverpil / find_and_delete_removeVrayEnvironmentPreviewTm.py
Last active August 29, 2015 13:57
Find any VrayEnvironmentPreviewTm nodes and remove them #maya
import maya.cmds as cmds
def removeVrayEnvironmentPreviewTm():
# Are there any vrayEnvironmentPreviewTm nodes?
try:
cmds.select('vrayEnvironmentPreviewTm*', r=True)
nodesFound = cmds.ls( selection=True )
textMessage = 'Nodes found:\n\n'
for node in nodesFound:
@fredrikaverpil
fredrikaverpil / listAttr.py
Created March 25, 2014 13:38
Get all attributes of object #maya
import maya.cmds as cmds
for attribute in (cmds.listAttr("vraySettings")):
print attribute