PDA

View Full Version : Maya Attributes problem


Axisphere
05-24-2005, 02:01 PM
Hi guys I have two questions to ask,

1. In Maya 6.5 when you vertex lighting or prelight something it seems to switch off realtime lights from affecting the objects, I need this because we use 1 ambient light in our company to light the level and the vert colours as our lighting, but maya seems to disable any lights from affecting anything with vert lights on, I found a fix for this by selecting an object hitting Ctrl+A to bring up the attribude editor and selecting Display Immediate tag under Mesh Component display....but you have to do it on an object by object basis which is not do-able for a level with 1000's of objects so....

2. How do I put an attribute on multiple objects or objects I have selected?, I have the mel for the attribute but it wont apply to all objects or objects I have selected.

Any Ideas?

MSB
05-24-2005, 03:03 PM
well you can post the mel so we can fix it at least

and

why not to using the attribute spread sheat?

Axisphere
05-24-2005, 03:09 PM
The mel is as follows

setAttr "pSphereShape2.displayImmediate" 1;

this only works on the object pShereShape2 i have editied it to

setAttr ".displayImmediate" 1;

Which works fine on one selected object but does not work on a group of slected objects..... Looked at the attributes spreadsheet and couldnt find it in there....

Iconoklast
05-24-2005, 03:48 PM
you'll need to create a loop of your objects using mel, so for example

string $selected[] = `ls -sl`; // get what's selected

for ($obj in $selected) // loop through the selected, and for every object in the selection..
{
string $objShape[] = `listRelatives -s $obj`; // get the shape name of the object
setAttr ($objShape[0] + ".displayImmediate") 1; // and set displayImmediate to 1.
}

Axisphere
05-24-2005, 04:29 PM
Thanks man that worked a treat, I know nothing of MEL and so it made no sense to me whatso ever, could you if you get the time break that script down and tell my why it worked?

Again thanks

Chris -Axisphere-

Iconoklast
05-24-2005, 05:01 PM
Sure mate. I hope I can make it make sense..

1) First, we need to get the objects you have selected. In mel (as with every other language), you need to declare your variables. So to start with, we declare the variable $selected. the '[]' at the end means it's an "Array". An array basically stores multiple values. 'String' just means it's text, rather than a number. So, after we've defined $selected (Note that anything with a dollar sign($) in mel, is a variable), then we must put what we want in this variable. What we want a list of selected objects. In this case `ls -sl`, basically translates to `list -selected`. You need the ` ` dashes before and after command. I can't explain why, you just do :P.
string $selected[] = `ls -sl`;
For example. If you have pCube1, and pSphere1 selected, doing the above will store pCube1 and pSphere1 in the string array $selected. Which we can then refer individually at a later stage.

2). Here what we need to do is create a loop, or basically a cycle, which takes every single object in the variable $selected, and for each objects runs a certain amount of command. The for loop keeps running until it reaches the end of the string array. In our previous example, a for loop would run twice, because there is pCube1 and pSphere1 in the string array. In this case, if we were to translate the below command into english, it would be something like.
For every object in the selection list, do <whatever we want>. We don't need to 'declare' $obj, because it's already declared in the 'for' command. Make a note that you NEED the { after every for loop, because otherwise you'll get syntax errors. You'll need to close the for loop with } at the end of the code.
for ($obj in $selected)
{

3). Because in Maya there are two elements of an object. There's the transform, and the shape node. For example, if you have pCube1. pCube1 is the transform, and pCubeShape1, is the shape node. Depending on what you need to do, you need to refer to either the shape or the transform. In this case, we want the shape node. So below, we're declaring another string variable called $objShape. And we're storing the shape node of the $obj (object).
string $objShape[] = `listRelatives -s $obj`;
Using previous examples. For the first loop, $obj will be pCube1. Which means, we'll run listRelatives -shape pCube1. Which will return pCubeShape1, and store this in $objShape to access later.

4). This is where we set the attribute. Because we're in a for loop, the loop will set the attribute for each $obj. Because we're accessing the shape node, instead of the transform node, we need to access $objShape, NOT $obj. You'll notice I have $objShape[0]. In a string array, each index (or item in the array) has a number assigned to it. In our example, pCubeShape1 is the only item to be returned from the `listRelatives -s` command, because pCube1 will normally only have 1 shapenode. It is assigned 0, instead of 1, because arrays always start with 0. When using setAttr and arrays, we need to do the whole ( object + ".attribute") otherwise you'll get a syntax error.
setAttr ($objShape[0] + ".displayImmediate") 1;

5). here we close the loop, using }.
}

I may have gotten a bit complex here, but go out and do a bit of research on mel, come back, and it should make sense to you.. Hopefully! I'm not very good at explaining sometimes. :blush:

A-OC
05-24-2005, 11:04 PM
Thanks Iconoklast, that's so cool you contribute like this to the community. What would you recommend to learn mel ?

Iconoklast
05-25-2005, 06:20 AM
Hmm, I'm trying to remember how I got a pretty good grip of mel.. I had learned a bit of C programming, which is pretty similar to MEL, then I did a bit of research here and there, websites like www.ewertb.com (http://www.ewertb.com) are very helpful, however, I think what has helped me the most was, I had this script I wanted to write, and I pretty much just dissected those scripts to see how they worked, and apply bits and pieces to my own script. Also writing little scripts, such as toggling xray, or shaded, etc, are really good to help you understand a bit how maya works and the control you have.

CGTalk Moderation
05-25-2005, 06:20 AM
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.