View Full Version : select shadingGroups problem

11 November 2011, 07:13 AM
hi! I just trying to select all shadingGroups and change some mental ray tab attributes like enable contour , but just change the last selection , I dont know whats wrong!

if ( `window -exists contourWin` ) {
deleteUI contourWin; // delete window when it exists

window -title "CONTOUR" -widthHeight 200 100 contourWin;

string $mySel[] = `ls -sl`;
string $shapes[] = `listRelatives $mySel`;

string $myMaterial[] = `listConnections -type "shadingEngine" $shapes`;

checkBox Contour;

text -l "alpha:";
floatField alpha_linia;

text -l "grosor:";
floatField grosor_linia;

for($mat in $myMaterial)

connectControl Contour ($mat+".miContourEnable");

connectControl alpha_linia ($mat+".miContourAlpha") ;

connectControl grosor_linia ($mat+".miContourWidth") ;

showWindow contourWin;

11 November 2011, 10:27 AM
you can connect multiple attributes to one control, but only all at once. What you are doing is looping through setting it to one attribute after the other. when it's finished it's only connected to the last one (the previous connection was overridden every time you did a new connection).

if you want to use this approach you will have to construct a command string containing all the attr names and then eval it.

An alternative approach may be to make a control (i.e. checkBox) that simply fires off a function on change, this function then gets all the nodes you want to modify and sets the attribute accordingly. This is potentially more versatile, but isn't two-way (in other words, if you change the attribute, the control doesn't update)


11 November 2011, 10:24 AM
seems I cant connect multiple attributes using a string list selection array or something like that , only works connecting one object ,

even this simple mel i found to scale selected objects

if ( `window -exists scaleWin` ) {
deleteUI scaleWin; // delete window when it exists

window -title "scale" -widthHeight 200 100 scaleWin;
string $selected [] = `ls -sl`;
columnLayout -adjustableColumn true

columnLayout -adjustableColumn true

attrFieldSliderGrp -p secondCol
-l "Scale X :"
-attribute ($selected[0]+".sx")
-minValue -10.0
-maxValue 10.0
showWindow scaleWin;

but if try change "selected[0]" to "selected[]" to can scale all selected objects then get error ,
Im not a mel worker so maybe Im making a silly question but just cant understand why cant get it work for multiple objects

11 November 2011, 12:43 PM
you can't add ".sx" (which is a single explicit string) to an array. From a purely logic point of view it's nonsense, or at very best ambiguous. What you have to do is add ".sx" to the end of each element in that array.
string $attrArray[] = {}; // start with an EMPTY array
for ($item in $selected) // loop through the selection
$attrArray[size($attrArray)] = ($item + ".sx"); // append ".sx" and add this new string to our array
// now you have an array of "object.attribute" strings you can pass to the connect command:
connectControl "name" $attrArray;

bear in mind though, that the attrFieldSliderGrp command DOES only take ONE attribute, whereas connectControl allows multiple.

CGTalk Moderation
11 November 2011, 12:43 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.