AREA forums upgrade
Read more about the planned upgrade of our forums
  • 1/3
You are here: Forum Home / Autodesk® Maya® / Python / Materials export in Python?
IMPORTANT ANNOUNCEMENT ABOUT AREA FORUMS
  RSS 2.0 ATOM  

Materials export in Python?
Rate this thread
 
68334
 
Permlink of this thread  
avatar
  • Ilya81
  • Posted: 19 June 2012 11:43 PM
  • Location: St-Petersburg
  • Total Posts: 1
  • Joined: 19 June 2012 11:32 PM

I need to export Maya scene into own application. And I’ve got problems with materials. I’ve found over the Web a working example that I’ve used for the base:

mesh.getConnectedSetsAndMembers(instanceNumbersetscomponentsTrue)
 
file.write("<MeshMaterials>")
 for 
i in range(sets.length()):
 
material Material()
 
set sets[i]
 component 
components[i]
 fnSet 
maya.OpenMaya.MFnSet(set)
 
dependencyNode maya.OpenMaya.MFnDependencyNode(set)
 
surfaceShaderAttribute dependencyNode.attribute("surfaceShader");
 
surfaceShaderPlug maya.OpenMaya.MPlug(setsurfaceShaderAttribute)
 
sourcePlugArray maya.OpenMaya.MPlugArray()
 
surfaceShaderPlug.connectedTo(sourcePlugArrayTrueFalse)
 if 
sourcePlugArray.length() == 0:
 continue
 
sourceNode sourcePlugArray[0].node()
 
materialDepNode maya.OpenMaya.MFnDependencyNode(sourceNode)
 
material.Name materialDepNode.name()

 if (
sourceNode.hasFn(maya.OpenMaya.MFn.kLambert)):
 
lambertShader maya.OpenMaya.MFnLambertShader(sourceNode)
 
presaveLambertShaderDiffuseColor(materiallambertShader)

But there are also common material attrbiutes that I need to export also, but I don’t know how to access them. If I write

if (sourceNode.hasFn(maya.OpenMaya.MFn.kMaterial)):
 
baseMaterial maya.OpenMaya.MMaterial(sourceNode)
 print 
baseMaterial.color

I never see the output, i. e. the node never can be used to create MMaterial. And I don’t know how to access it some other way.

Tell me please how can I export common material attrbiutes.



Replies: 0