Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® Maya® / Python / Get image size?
  RSS 2.0 ATOM  

Get image size?
Rate this thread
 
63537
 
Permlink of this thread  
avatar
  • ramses06
  • Posted: 12 January 2012 09:04 PM
  • Total Posts: 2
  • Joined: 12 January 2012 08:56 PM

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.



Replies: 0
avatar
  • tkaap
  • Posted: 13 January 2012 02:53 AM

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"pathtype="string")
  
wPixels m.getAttr(fileNode+".osx") / 10.0
  hPixels 
m.getAttr(fileNode+".osy") / 10.0
  
if name:
    
polyNode m.polyPlane(w=wPixelsh=hPixelssx=1sy=1,name=name)[0]
  
else:
    
polyNode m.polyPlane(w=wPixelsh=hPixelssx=1sy=1)[0]
  
  lambertNode 
m.shadingNode("lambert"asShader=1)
  
m.connectAttr(fileNode+".outColor"lambertNode+".color")
  
sgNode m.sets(renderable=1noSurfaceShader=1, empty=1name=lambertNode+"SG")
  
m.connectAttr(lambertNode+".color"sgNode+".surfaceShader",f=1)
  
m.sets(polyNodee=1fe=sgNode)


Replies: 0