better : cannot open# Error: line 1: NameError: file <maya console> line 
18: name 'img' is not defined # 

with this code

import os
import maya.cmds as cmds
from PIL import Image

#change the path here
path = "/Users/francesco/Desktop/selectionMaya"

#list the items in the folder
dir = os.listdir(path)

junk = [".mayaSwatches", ".DS_Store", ".picasa.ini"]

for texture in dir:
    if texture not in junk:
try:
img = Image.open(texture)
except IOError:
print 'cannot open', img
#Get Ratio
        #img.size[0] -> width
        #img.size[1] -> height
        #ratio = img.size[0]/img.size[1]

        #create a nurbsPlane for each texture
        mesh = cmds.nurbsPlane(name = texture)
        #create a shader
        shader=cmds.shadingNode("blinn",asShader=True)
        #a file texture node
        name = texture.split(".")[0]
        file_node=cmds.shadingNode("file", name = "file_" + name, 
asTexture=True)
        #assign a texture
        cmds.setAttr( "file_" + name +'.fileTextureName', path +'/'+ 
texture, type="string")

        # a shading group
        shading_group= 
cmds.sets(renderable=True,noSurfaceShader=True,empty=True)
        #connect shader to sg surface shader
        cmds.connectAttr('%s.outColor' %shader ,'%s.surfaceShader' 
%shading_group)
        #connect file texture node to shader's color
        cmds.connectAttr('%s.outColor' %file_node, '%s.color' %shader)
        cmds.select(mesh)
        cmds.hyperShade( assign=shader)



Le mardi 3 mars 2015 17:13:41 UTC+1, francois bonnard a écrit :
>
> Hey folks
>
> I am running Maya 2014 os windows 8.1 64 bits.
>
> I have dowloaded python PIL from this URL 
> <https://mistermatti.wordpress.com/2014/02/04/maya-2014-with-pythons-pil-module/>
>  and 
> have installed the folder with the files in 
> ...maya2014/python/Lib/site-packages/
>
> Here is my script :
>
> import os
> import maya.cmds as cmds
> from PIL import Image
>
> #change the path here
> path = "/Users/francesco/Desktop/Géosésame/Maya/sourceimages/selectionMaya"
>
>
> #list the items in the folder
> dir = os.listdir(path)
>
> junk = [".mayaSwatches", ".DS_Store", ".picasa.ini"]
>
>
> for texture in dir:
>     if texture not in junk:
>         #Load Image in Pillow
>         img = Image.open(texture)
>  #create a nurbsPlane for each texture
>         mesh = cmds.nurbsPlane(name = texture)
>         #create a shader
>         shader=cmds.shadingNode("blinn",asShader=True)
>         #a file texture node
>         name = texture.split(".")[0]
>         file_node=cmds.shadingNode("file", name = "file_" + name, 
> asTexture=True)
>         #assign a texture
>         cmds.setAttr( "file_" + name +'.fileTextureName', path +'/'+ 
> texture, type="string")
>
>         # a shading group
>         shading_group= 
> cmds.sets(renderable=True,noSurfaceShader=True,empty=True)
>         #connect shader to sg surface shader
>         cmds.connectAttr('%s.outColor' %shader ,'%s.surfaceShader' 
> %shading_group)
>         #connect file texture node to shader's color
>         cmds.connectAttr('%s.outColor' %file_node, '%s.color' %shader)
>         cmds.select(mesh)
>         cmds.hyperShade( assign=shader)
>
> Here is the issue :
>
> # Error: line 1: IOError: file C:\Program 
> Files\Autodesk\Maya2014\Python\lib\site-packages\PIL\Image.py line 1952: 2 
> # 
>
> Obviously the issue is on this line : 
>
> img = Image.open(texture)
>
> What Do I miss ?
>
> Thanls for the help
>
> Fransua
>
>
>

-- 
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/3ba5421f-084f-48ad-93b7-860a32a835af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to