PDA

View Full Version : how to -RE-source python file ?


claudiod
07-31-2012, 02:00 PM
I got a pythonfile right in the PYTHONPATH as I posted on below of this thread
it displays a window.when I import it via "import rv_texture_path_fix"
but second time no window opening.

in mel it reimports and executes via <source>.but this is python and I didnt understand why it doesnt show anything.

any clue about this problem?


import maya.cmds as cmds
import os

def renameTex(newName):
tex=cmds.ls(sl=True,type="file")
for item in tex:

fullpath = cmds.getAttr("%s.fileTextureName" %item)
fileName= fullpath.split("/")[-1]
newPath= os.path.join(newName,fileName)
cmds.setAttr("%s.fileTextureName" %item, newPath,type="string")

def selectDir():
folder=cmds.fileDialog2(cap="locate folder",fm=3)
uniToStr=str(folder)

filePath=uniToStr.split("'")[1]
cmds.textField(pathText, edit=True,text=filePath)
global newName
newName=filePath

win=cmds.window(title="RV TEXTURE PATH FIX",w=350,h=150)
cmds.columnLayout(adjustableColumn=True )
cmds.text("FIRST > select your file nodes in Hypershade!!",bgc=(1,0,0))
cmds.frameLayout(l="browse folder for textures")
cmds.flowLayout()
cmds.text("file Path",h=25)
pathText=cmds.textField(w=250,h=25)
loadBtn=cmds.button(w=50,h=25,label="get",c="selectDir()")

cmds.setParent( '..' )
fixit=cmds.button(l="Fix textures", c="renameTex(newName)")
cmds.setParent( '..' )

cmds.showWindow(win)

Gromit2010
07-31-2012, 02:18 PM
If you want to re-source a python file you need to reload the module.

Http://docs.python.org/library/functions.html#reload

rgkovach123
07-31-2012, 02:46 PM
There are two ways to do it.

If you have a single python file use this:

try: reload(my_pythonscript)
except: import my_pythonscript

if you are using modules/packages, then you need the reimport module (you may have to download it separately - i don't think it is part of the main python install).

import reimport
import my_pythonpackage as mine
reimport.reimport(mine)

TDgirl
07-31-2012, 04:26 PM
You could put your window code into a single function:

def menu():
win=cmds.window(title="RV TEXTURE PATH FIX",w=350,h=150) cmds.columnLayout(adjustableColumn=True )
cmds.text("FIRST > select your file nodes in Hypershade!!",bgc=(1,0,0)) cmds.frameLayout(l="browse folder for textures")
cmds.flowLayout()
cmds.text("file Path",h=25)
pathText=cmds.textField(w=250,h=25) loadBtn=cmds.button(w=50,h=25,label="get",c="selectDir()") cmds.setParent( '..' )
fixit=cmds.button(l="Fix textures", c="renameTex(newName)") cmds.setParent( '..' )
cmds.showWindow(win)

then do:

from rv_texture_path_fix import menu
menu()

more generic:

from scriptName import mainFunction
mainFunction() # call the function

(sorry for my indentation mistakes!!)

claudiod
07-31-2012, 07:58 PM
thank all of you!

CGTalk Moderation
07-31-2012, 07:58 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.