import osimport maya.cmds as cmdsfrom PIL import Image
#change the path herepath = "/Users/francesco/Desktop/Géosésame/Maya/sourceimages/selectionMaya"
#list the items in the folderdir = 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)--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/a7e7c289-b5e4-4fd1-a7c2-c20b511b074d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/bf7994c5-8580-4f35-86f9-d2d582527bff%40googlegroups.com.To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
I got this message : # Error: line 1: unindent does not match any outer indentation level #
import osimport maya.cmds as cmdsfrom PIL import Image
#change the path herepath = "/Users/francesco/Desktop/selectionMaya"
#list the items in the folderdir = 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]import osimport maya.cmds as cmdsfrom PIL import Image
#change the path herepath = "/Users/francesco/Desktop/selectionMaya"
#list the items in the folderdir = 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)--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/2c28eaf1-4a7f-4433-a552-631ff38a17ec%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ED9A4F7C-BC57-40AE-B983-BF5CA20F9EBD%40gmail.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/n6pOGdlhJjs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ED9A4F7C-BC57-40AE-B983-BF5CA20F9EBD%40gmail.com.
I will stop you.
A standalone python has nothing to do with the problem as you are using the embedded python version within Maya.
You seem to be bounding between PIL issues and standard python user syntax errors. My suggestion would be to simplify and confirm you can open a basic image in PIL. Just try to successful open an absolute path to one of your images, on a single line in your script editor. Maybe you are trying to open a format not supported by PIL.
In your most recent user error, when you catch an exception from failing to open a file, you forget to "continue" and allow the rest of the following code to operate on the "img" variable that was never defined.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAB%3DHRHAFCtpBhUm1fVbSqhdG4%3D%3D_bCmRGqyP1c9e%3DrL94AcvJA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA21wuOvw0-zB0vy5vgvvP2W0eX_AmN%2Bn-nojTOdcMOKEA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAB%3DHRHB-GObsqRk9gWhC2Q_%2BsUV8KLYxiXGHXEN2r0608cp-Xg%40mail.gmail.com.
Ok, slow down a little. Let’s take this one step at a time.
os.path.isfile takes a path as input. If that path is not absolute - i.e. does not have the root/drive-letter included - then it will assume that the string you gave it is relative to the current working directory, which typically is the directory from which you run the script.
For example, if you are here:
c:\
And you pass a filename, such as a.jpg to os.path.isfile, then os.path.isfile will assume that you meant:
c:\a.jpg
To instead have it look inside your selectionMaya directory, you will have to pass the full path instead.
>>> import os
>>> full_path = os.path.join("C:/Users/francesco/Desktop/selectionMaya", "a.jpg")
>>> print os.path.isfile(full_path)
True
--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/n6pOGdlhJjs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODJVZPStx5kvMT4H70A0eXdjVCpNSHKr6FT-0Yyro4bOA%40mail.gmail.com.