|
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)[0]
else:
polyNode = m.polyPlane(w=wPixels, h=hPixels, sx=1, sy=1)[0]
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)
|