Texture channel/resolution question

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
Old 01 January 2013   #1
Texture channel/resolution question

Hey guys!
I'm wondering if someone of you guys can help me to change Texture channel and Texture resolution attribute values in Shader via mel/python. I've tried to use what Maya says in script Editor when changing this values via UI but without success.
Render Monkey
Old 01 January 2013   #2
This is actually not quite trivial. I've scanned the MEL files involved, and there's a lot going on behind the scene.

Most importantly, all the functionality is built into local procedures in that MEL file, so you can't access them from your own scripts.

Instead of trying to replicate the MEL code that the developers put in there (which would be timeconsuming and rather complex), I suggest simply interacting with the given UI via MEL, i.e. make Maya believe you actually clicked on the channels or resolution menus.

Because the actual code gets invoked on the -selectionChanged command of the optionMenuGrp (the dropdown menu in the attribute editor), simply changing what value is selected via MEL will do the trick:

// define the shader you want to perform this procedure on $shader = "lambert2"; // select it so it displays in the Attribute Editor select $shader; // get its nodeType (e.g. lambert, blinn, etc.) $shaderType = `nodeType $shader`; // create the name for the menu attached to this AETemplate's Texture Channel $channelMenu = ($shaderType + "_channelMenu"); // create the name for the menu attached to this AETemplate's Texture Filter $qualityMenu = ($shaderType + "_qualityMenu"); // now we can select the values we'd like // note that $_Value have to be set to valid values you'd find in that menu // valid channels are "None", "Color", "Transparency", etc. string $channelValue = "Color"; // valid quality values are 1 - 5 (Default, Low ... Highest) int $qualityValue = 5; // set the Texture Channel. Note that if no texture is connected to the Channel // you defined, the value will jump back to the previous value or "None" if(`optionMenuGrp -q -ex $channelMenu`) { // we eval Deferred so that the code doesn't get executed before the AE UI is built evalDeferred("optionMenuGrp -e -value " + $channelValue + " " + $channelMenu); } // set the Texture Resolution. Note that this is only possible if // a texture is actually connected to the shader if( (`optionMenuGrp -q -ex $qualityMenu`) && (`optionMenuGrp -q -en $qualityMenu`) ) { evalDeferred("optionMenuGrp -e -select " + $qualityValue + " " + $qualityMenu); }

See if that does the trick for you. It's a rather ugly hack but given the right circumstances (i.e. prior knowledge of your shader and its texture connections) it should work.

Making this more robust would involve querying to see what kind of textures are connected to which channels on your shader and only executing certain code if a given set of conditions is met; after all, you can't change the resolution on a texture if there is no texture connected to that particular channel; also, it is not valid to select a channel that has no texture connected to it.
Old 01 January 2013   #3
Wow! Thank you very much! Broke my brain looking for solution . Your code works perfectly! Like you said valid channels are only "None", Color" and "Transparency". But what about "Combined Textures"? I get error about arguments - expected 1 but got 2 instead.
Render Monkey
Old 01 January 2013   #4
Please paste the error from Maya so I can take a look.
Old 01 January 2013   #5
Here is the error and the line where it occurs:
optionMenuGrp -e -value Combined Textures lambert_channelMenu; // Error: line 1: Too many arguments. Expected 1, found 2. //

I have changed "Color" to "Combined Textures"
Render Monkey
Old 01 January 2013   #6
you have to enclose it in quoatation marks "":

optionMenuGrp -e -value "Combined Textures" lambert_channelMenu
Old 01 January 2013   #7
Thank you! Now it works perfectly. I guess this is because "Combined Textures" is two strings and "Color" only one.
Render Monkey
Old 01 January 2013   #8
Thread automatically closed

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.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 01:08 PM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.