I'm a little confused.   I tried running your script and it most definitely 
didn't work (for more than a few reasons) but it seems like you're very 
confused about what functions to use and where.  I've converted your script 
to PyMel (just to show, and also modified the cmds version).  Seems like 
you think you're working with actual "files" but in reality the "file" is 
really just a path as a string not a system file.  So you would just do 
either string manipulation or use manipulate with os.path functions.  You 
don't need to use copy2 as a function since that's more of an actual system 
file command rather than string manipulation.  (I also added in the way to 
get your PROJECT environment variable for fun.

*PYMEL*
  
*import pymel.core as pm*
* *

*import os*
* *

*files = pm.ls(type="file")*
* *

*project_path = os.getenv('MAYA_PROJECT')*
* *

*def myCopy (path):*
* *

* return path.replace('/','') #does both / and //...*
* *

*for item in files:*
* *

* fileNode = pm.PyNode(item)*
* *

* fileNode.fileTextureName.set(myCopy(project_path), type='string') 
#setting the new path*
* *

* print fileNode.fileTextureName.get() #echos back old file path!!!!!!!*
*CMDS*
  
*import maya.cmds as cmds*
* *

*import os*
* *

*files = cmds.ls(type="file")*
* *

*project_path = os.getenv('MAYA_PROJECT')*
* *

*def myCopy (path):*
* *

* return path.replace('/','') #does both / and //...*
* *

*for item in files:*
* *

* cmds.setAttr( "%s.fileTextureName"%item, myCopy(project_path), 
type='string') #setting the new path*
* *

* print cmds.getAttr( "%s.fileTextureName"%item) #echos back old file 
path!!!!!!!*


On Wednesday, October 23, 2013 10:34:53 AM UTC-4, Aleks Berland wrote:
>
> Hi guys!
> I'm newish to python in maya, and new to this discussion group. Thanks for 
> reading my topic!
>
> Ok so I have a unique issue, tested in Maya 2013.0 x64.
>
> Issue is I have a python script, reassigning texture paths and when the 
> script is run on an opened file that changes are made to the path of the 
> texture AND the file scene is saved, AND the path is visibly there... 
> When the script is run, that fileTextureName node WILL NOT ACCEPT a 
> setAttr var and remains UNMODIFIED.
> However, if you reopen that saved file in a fresh maya session, the script 
> works perfectly.
> Following is some example code:
>           
>          * import maya.cmds as cmds*
>
> *files = cmds.ls(type="file")*
>
> *          project_path = "/wherever"*
> *          *
> *         def myCopy (path, newpath):*
> *              copy2(path, newpath)*
> *              #example of doin somethin to  path.. can be commented out 
> as the return i get in my function prints back below*
> *              dosomethingtothepath = newpath.remove('\\','\')*
> *              return **dosomethingtothepath*
>  
>
> *for item in files: *
>
> *    fullpath = cmds.getAttr('%s.fileTextureName' %item)*
>
> *    newpath = myCopy(fullpath, project_path) #mycopy uses copy2 and 
> returns the new path*
>
> *              print "Copied: " + fullpath + " to: " + newpath #newpath 
> echos back correctly here from mycopy function!!!*
>
> *    cmds.setAttr("%s.**fileTextureName**" %item, newpath,type="string") 
> #setting the new path*
>
> *              print cmds.getAttr('%s.fileTextureName' % (item) #echos 
> back old file path!!!!!!!*
> *
> *
> *
> *
> So to recreate the scenario:
> 1.  create simple maya scene with primitive and shader with texture. Save 
> scene.
> 2. edit the project path var so it goes somewhere on your system. run this 
> script.
> 3. should work correctly first time. so change the texture to some other 
> file in shader, then save. run script... see? attribute not changed as 
> visible in listener.
> 4. close maya. reopen. reopen modifed saved scene. run script. it works.
>
> One other note is that the final path i am assigning in newpath DOES NOT 
> EXIST locally, though I am not sure this makes a difference.
>
> Thanks for taking time to read about my troubles.
>
> - Aleks
> *
> *
> *
> *
>
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/1e6ebca2-90ad-41cb-9cae-87cea3c808a8%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to