View Full Version : Changing Materials throught a Ctrl

06 June 2007, 05:57 AM
Well, ive been workin on a rig for a character of mine, and i wanted to be able to change the entire shader of a couple of objects with just switching "on" or "off" on an attribute on a controller object. For example:

if (Ctrl.Shader = 1)
object1.shader = dilectricshapenode
object1.shader = blinn1;

For example. *i know the code doesnt make sense, lol, just for reference*

Ive been watching the script editor when i assign a shader to an object, but the code there doesnt seem to work on the Expression editor... any ideas?

10 October 2007, 07:05 PM
im searching the same, with an attribute can say when attrb is 0 assign this shader when its 1 assign that... I have tested some things but nothing works.... :(

10 October 2007, 04:53 PM
If you're not using a GUI, you're going to have to use a scriptJob in combination with mel scripts. **Edit: Make sure you read the docs on scriptJobs, they can be dangerous.

So this:

scriptJob -attributeChange mySphere.customAttribute shaderChangingProcedure;

And in your procedure, just do an if/else statement querying the value of mySphere.customAttribute

10 October 2007, 05:07 PM
yep the script job is the way to go.

as well, another way would be to plug all the shaders through a layered shader
and use the driven key to switch the layerOpacity based on your ctrl.shader

10 October 2007, 01:13 PM
As Norb already pointed out, you could also use a simple GUI for this.
Something like this:

window -h 30 -w 40;
checkBox -label "Toggle material"
-cc "if (`checkBox -q -v checkbox1`==0) hyperShade -assign matBlue; else hyperShade -assign matGreen;" checkbox1;

CGTalk Moderation
10 October 2007, 01:13 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.