Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Get image size?

Get image size?

Anonymous
Not applicable
988 Views
1 Reply
Message 1 of 2

Get image size?

Anonymous
Not applicable
hi

I have a project in python for my school.
My question is : How to get a image size in maya
For exemple I create a lambert material, I put a externe
file (texture). And I want to get the size of my texture
for create a plan with a good ratio.
0 Likes
989 Views
1 Reply
Reply (1)
Message 2 of 2

tkaap2
Autodesk
Autodesk
The .outSizeX and .outSizeY attrs on the file node will get you what you want.

This is my script to do just what you're asking about

import maya.cmds as m
import os.path
def createPlaneForTexture(path,name=False):
if not (os.path.exists(path)):
print "Error: file not found: "+ path + ", exiting"
raise IOError
return
fileNode = m.createNode("file")
m.setAttr (fileNode+".fileTextureName", path, type="string")
wPixels = m.getAttr(fileNode+".osx") / 10.0
hPixels = m.getAttr(fileNode+".osy") / 10.0
if name:
polyNode = m.polyPlane(w=wPixels, h=hPixels, sx=1, sy=1,name=name)
else:
polyNode = m.polyPlane(w=wPixels, h=hPixels, sx=1, sy=1)

lambertNode = m.shadingNode("lambert", asShader=1)
m.connectAttr(fileNode+".outColor", lambertNode+".color")
sgNode = m.sets(renderable=1, noSurfaceShader=1, empty=1, name=lambertNode+"SG")
m.connectAttr(lambertNode+".color", sgNode+".surfaceShader",f=1)
m.sets(polyNode, e=1, fe=sgNode)
0 Likes