forked from lookbothways/vfxTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoSED
104 lines (82 loc) · 3.28 KB
/
autoSED
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import maya.cmds as cmds
import pymel.core as pm
import subprocess
"""
import autoSED
reload(autoSED)
# for shelf
doit = ""
searchFor = ""
replaceWith = ""
filePath = ""
filePath = AUTOsed.start()
"""
def createWindow(filePath):
#Creates a window in maya
# runs queryTextField
windowID = 'autoSED'
if cmds.window(windowID, exists = True):
cmds.deleteUI('autoSED')
window = cmds.window(windowID)
cmds.rowColumnLayout()
cmds.textFieldGrp('searchFor', label = 'Search for: ')
cmds.textFieldGrp('replaceWith', label = 'Replace with: ')
#cmds.button(label = 'pass textfield values', command = queryTextField)
#cmds.button( label='Search and Replace', command=('queryTextField(filePath);cmds.deleteUI(\"' + window + '\", window=True)') )
cmds.button('search_and_replace_btn', label='Search and Replace', command=pm.Callback(search_and_replace_btn_clicked, filePath, window))
cmds.showWindow( window )
return filePath
def search_and_replace_btn_clicked(filePath, window):
"""
Gets called when the "Search and Replace" Button is clicked.
:param str filePath: The file path on which to operate on.
:param str window: The name of the window that this button lives in.
"""
queryTextField(filePath)
cmds.deleteUI(window, window=True)
def swapPaths(filePath,searchFor,replaceWith):
niceFilePath = filePath[3:-2]
splitPath = niceFilePath.split("/")
fileName = splitPath[-1]
splitDirectory = niceFilePath.split("/")
justFilePath = splitDirectory[:-1]
fileDirectory = "/".join(map(str,justFilePath))
# Create the command for the terminal
command1 = "find "+ fileDirectory +" -maxdepth 1 -name '"+ fileName +"' -exec sed -i 's!"+searchFor+"!"+replaceWith+"!g' '{}' \;"
finalCommand = command1# + " && " + command2
print "Command being passed to the terminal: \n", finalCommand
# Pass the commands to a shell
subprocess.Popen(finalCommand, shell=True)
print "Auto-SED complete for file: %s" % fileName,
def queryTextField(filePath):
# Gets the contents of the fiels in 'createWindow'
# Runs swapPaths
searchFor = cmds.textFieldGrp( 'searchFor', query = True, text = True)
replaceWith = cmds.textFieldGrp( 'replaceWith', query = True, text = True)
doit = cmds.confirmDialog(m="Search and replace?\n\n{}\n\nfor\n\n{}\n\nIn: {}\nThis is not undoable.".format(searchFor,replaceWith,filePath[3:-2]), b=["OK","Cancel"], icn="warning", ma="center", t="autoSED")
if doit == 'OK':
print "Searching {} for: {}. Replacing with: {}".format(filePath[3:-2],searchFor,replaceWith),
swapPaths(str(filePath),searchFor,replaceWith)
return searchFor, replaceWith
if "/mnt/" in filePath:
print "Running autoSED"
createWindow(filePath)
return filePath
else:
print "File not on /mnt/",
def getFilePath():
fileFilter = "Maya Files (*.ma *.mb);;Maya ASCII (*.ma);;Maya Binary (*.mb);;All Files (*.*)"
filePath = str(cmds.fileDialog2(ds=2, cap="Choose a file to search & replace in.", ff=fileFilter, fm=1, okc="This file", cc="Cancel"))
return filePath
def start():
filePath = getFilePath()
print filePath
createWindow(filePath)
return filePath
"""
doit = ""
searchFor = ""
replaceWith = ""
filePath = ""
filePath = start()
"""