Hi fellow Maya Programmers!
I need some help figuring out a script's filepath from within maya using python. I have a certain script file located somewhere on my harddrive. Let's assume the file is called "C:/Users/Username/Desktop/test.py". In Maya's Script Editor I open the script file using "File" -> "Open Script..." Menu. A new Tab in my script editor appears, displaying the content of my test.py. What I am trying to do now, is run the test.py and print the folder location where that file (test.py) is stored.
Is there anyway to extract that path information?
Thanks in Advance!
Solved! Go to Solution.
Solved by jmreinhart. Go to Solution.
import maya.cmds as cmds
def getScriptEditorPaths():
# Get the name of the scriptEditorPanel
allPanels = cmds.getPanel( all=True )
scriptPanel = [x for x in allPanels if 'scriptEditor' in x]
if not scriptPanel:
return []
scriptPanel = scriptPanel[0]
# Step through the layouts of the script editor until we find the tablayout
f1 = cmds.layout(scriptPanel, q = True, childArray = True)
f1, f2 = cmds.layout(formLayout1, q = True, childArray = True)
p1 = cmds.layout(f2, q = True, childArray = True)
sf, p2 = cmds.layout(p1, q = True, childArray = True)
t1 = cmds.layout(p2, q = True, childArray = True)
filePaths = []
for eachChildLayout in cmds.tabLayout(t1, q = True, childArray = True):
scrollFieldExec = cmds.layout(eachChildLayout, q = True, childArray = True)
filePaths.append(cmds.cmdScrollFieldExecuter(scrollFieldExec, q = True, filename = True))
return filePaths
getScriptEditorPaths()
This should work 🙂
Hey man, thank you for your reply. unfortunately I get an error saying that global name "formLayout1" is not defined.
Okay, I actually fixed it by myself already. I replaced "formLayout1" with f1[0] :). It's working, thanks a lot!
Can't find what you're looking for? Ask the community or share your knowledge.