Dear Mel Gurus...(probably A Simple Answer...)

So..!

I've recently started to learn MEL, and I'm a bit confused about something. Consequently, I'm posting it on here, that one of the resident genuises who are far wiser and more experienced than I can hopefuly (quickly) explain this to me, and get me back on track.

alright, the question has to do with setting attributes for an array of polygonal spheres.

Imagine:

A set of spheres, maybe 3, what-have-you.

I want to adjust the radius of all spheres I select.

First, I would assume I must create an array of the spheres:

string $selected[] = ls -sl;
// Result: pSphere1 pSphere2 pSphere3 //

now, I would assume that I need to run a for-in loop, and to use setAttr somehow to adjust the radius?
The only problem I've run into (beyond being confused about syntax) is that I need to set the attribute on the shape node of each of the objects, correct? In which case, how do I go about returning the shape object from the objects selected from my array? If you have any hints here, they'd be greatly appreciated...

Looking forward to a response,

Brendan Bond

QUOTE(brendanjbon @ 12/16/07, 07:57 PM) [snapback]278203[/snapback]
The only problem I've run into (beyond being confused about syntax) is that I need to set the attribute on the shape node of each of the objects, correct?

Well, not quite. See the shape does not construct the sphere it contains a representation thats shaped like a sphere but the shape itself has no way of knowing that, it could be literary shaped like anything. The computer don't know what, you will find that the computer is quite literary oblivious of lot of stuff we take for granted.

Now the shape is connected trough history to a polySphere or a makeNurbSphere node. Now this node knows what radius means. Theres a catch, once the history is gone theres no way of knowing this. So you may be in situation where you indeed have a number of spheres but no way of doing this.

Theres a number of other complications on the way too. Such as not being able to know the actual radius by just finding the radius attribute, because the scale affects the end result and you cant really know what happens upstream. So a object that looks like a cube or a human can react to the radius as well. Its sufficient to say that its not very healthy for you think in these lines.

Anyway the base function is pretty standard maya connection traversal. Theres sevrel ways of attacking this, lets make a naive attack on the subject here and leave it at that:

ls("-et","makeNurbSphere","-et","polySphere",listHistory(ls -sl -dag -shapes));

but as is said theres not really intelligence in all this. But should contain aswers to all your questions. (ls can be used to convert selections to other selection as the outermost ls shows).

You're absolutely correct..!

Thanks for solid advice. It was clear enough that I understand exactly what you mean. I suppose, syntactically I'm more at the stage of trying to figure out how things work than the best approach in which to make them work. In this instance, I was beginning to work on looping, and thought this would be an interesting self-imposed "assignment" to give myself. In retrospect, though, I can see what you mean

i'd say something like this..

CODE
string $selected[] = ls -sl;
// Result: pSphere1 pSphere2 pSphere3 //

for($n in  $selected){

setAttr $n+"scaleX 5;

}

Yes that works but its not exactly what he asked now is it

okay here's how i would do it

CODE
for($n in ls -sl){

setAttr ($n+".radius") 2;

}

more like:

CODE
for($n in ls("-et","makeNurbSphere","-et","polySphere",listHistory(ls -sl -dag -shapes))){

setAttr ($n+".radius") 2;

}