View Full Version : Applying textures to geometry via script
01-10-2011, 04:33 AM
Im currently experimenting with creating geometry and textures via script, and have succeeded so far, but I am stuck on how to 'apply' the textures to the geometry through script.
## Creating Background ## cmds.polyPlane(w=50, h=50, n="BackGround")
Any help would be greatly appreciated
01-10-2011, 05:57 AM
A shading group is basically a 'set'.
So you're looking for the 'set' command.
cmds.sets( 'pSphere1', e=True, fe='blinn1SG' )
01-10-2011, 11:09 AM
Ahh I see, thanks very much.......
So I've created the materials and assigned them using the 'sets' command as you suggested:
cmds.sets(renderable=True, empty=True, nss=True, n='MyShaderGroup1')
cmds.sets( 'pCube1', e=True, forceElement='MyShaderGroup1')
But say I had 60 pCube's (all named pCube1-60) and wanted to assign them the same shader group, would I have to write the cmds.sets('pCube1/2/3/4/4/5.....) command for each of them??
01-10-2011, 11:27 AM
cmds.sets( 'pCube*', e=True, forceElement='MyShaderGroup1')
or use a list, something like:cubes = cmds.ls(type='mesh')
cmds.sets( cubes, e=True, forceElement='MyShaderGroup1'):nathaN
01-10-2011, 11:34 AM
what NaughtyNathan said,
or if you want to select them first in case you either have other objects whose names start with 'pCube' (Nathan's first example) or other meshes in general (Nathan's second example) that you would want to exclude:
cubes = cmds.ls(sl=True)
cmds.sets (cubes, e=True, fe='myShadingGroup')
01-10-2011, 11:39 AM
Awesome! Yeh thats cool because what I can do is, have the objects created with a certain name then a number say 'dialCubes*' and then assign the texture to all of them using
cmds.sets( 'dialCubes*', e=True, forceElement='MyShaderGroup1')
Thanks very much to the both of you
01-10-2011, 12:40 PM
Bad news, I've got my code sorted for applying the textures to the geometry, which is:
cmds.shadingNode('blinn', asShader=True, n='secHandMat') cmds.setAttr('secHandMat.color', 1,0,0)
cmds.sets(renderable=True, empty=True, nss=True, n='MySGSecHand')
cmds.sets( 'secHand', e=True, forceElement='MySGSecHand')
But for some reason it will only work when hitting ctrl+enter within maya's script editor, where as when I try and run the script as a whole, it creates all the materials/shader groups but doesn't apply the materials to the geometry :s (attached image) also, it doesnt even give an error at command line.
Im too confused!
01-10-2011, 12:40 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.