PDA

View Full Version : setAttr madness! please save me


tredeger
10-13-2006, 06:34 AM
Thanks a tone in advance folks. I have some silly little syntactic problem in my code and it's driving me nuts. I've trying the monkeys at typewriters approach to finding the correct syntax and just can't hit it.

I have a multi attr called restPose. It's two children are restPoseTranslate and restPoseRotate. Each of those is a compound attr with X, Y, and Z components. So:

restPose
restPoseTranslate
restPoseTranslateX
restPoseTranslateY
restPoseTranslateZ
restPoseRotate
restPoseRotateX
restPoseRotateY
restPoseRotateZ

Now if i do a listAttr, all the attrs show up in the list so I know they are there. But I can't find the syntax to either getAttr or setAttr for the individual components. This isn't working:


setAttr multiWayConstraint1.restPose[0].restPoseTranslateX 5;

And none of the ridiculous permutations I've tried is working either. I keep getting the error:

// Error: No object matches name: multiWayConstraint1.restPose[0].restPoseTranslateX //

or some such. getAttr fails as well.

attributeExists will return true for the top attr (restPose) but false for the children (though, as I said, the children appear in the listAttr list). I really am confused by this.

Thanks and cheers,
j

Mikademius
10-13-2006, 09:51 AM
but it's an array... You'll have to type:



setAttr (multiWayConstraint1.restPose[0] + ".restPoseTranslateX") 5;

tredeger
10-14-2006, 02:47 AM
but it's an array... You'll have to type:



setAttr (multiWayConstraint1.restPose[0] + ".restPoseTranslateX") 5;



I'm afraid the problem isn't with where the quotes get placed. It's getting the right name so that maya recognizes it as a valid object. You're statement get's evaluated by maya the same as if you type:

"multiWayConstraint1.restPose[0].restPoseTranslateX"

It's just that this is not apparently a valid way of addressing the attr. Grrr. Arghhh.

In practice, I'll be breaking up the object name into variables and string parts but before I get that going, I've got to get the right object name to begin with. Thanks for the help though.

hibigibees
10-14-2006, 07:57 AM
hi,

I understand the issue which u r facing and I also understand that u have done a lot of homework in finding out the syntax for setAttr thingeee. !

I assume that u have created a vector attribute named restPose translate and restPose rotate on a node, for which u are trying to setAttr things...

BTW, just to reassure u I am just telling this method which I generally do for getting the code from the script editor, i.e. I select the node, make the attr keyable and when I am able to c the attribute in the channel box, I scrub and reset it to its original value. I open the script editor for the setAttr cmd which is usually;

setAttr "node.plug" 10;

---- so i copy the above code and paste it in my script editor and change the value to which I want my thing to work...

pls try this and reply ;)

tredeger
10-14-2006, 10:19 AM
Thank you everyone for your kind advice and generosity. I just wanted to let you know that I found the solution and that the problem was not with my syntax but with the fact that I am sleep deprived and foolish.

It turns out that the reason Maya would not allow me to connect to my attribute was that I had given it a short name that conflicted with one of the native attributes of the node. It would find the attr when I did a listAttr, but it wouldn't allow setAttr, getAttr, connectAttr to work on the node when refered to by it's long name. Referring to the short name would find the native attribute and not the one I had defined.

Wow! That little oversight was the cause of much pain and frustration. Maya gave no indication of this problem whatsoever. I might never have discovered this problem but for the fact that I had another attribute with a different name and no conflicts which was defined exactly the same way and which worked fine. So, I kept cutting, pasting, replacing and my changed attr kept failing. Finally I realized that the only difference in my definitions between one of my attrs that worked and one that failed was the short name. Checked by the short name in maya and found that it was taken. Problem solved. After much pain. Excruciating pain. And now embarrassment.

Thanks again for throwing your brain cells at the problems my foolishness creates.

hibigibees
10-14-2006, 10:27 AM
hi there,

thats cool u found the issue, usually i face this problem too...

so instead of coding
string $myvar[]=`ls -sl`;

i code
string $myvar[]=`ls -sl -l`;

which makes sure that the selected node(s) long name is stored in $myvar array...
this is always useful for scipting most of our requirement, i.e. just like being more specific to maya ..

sriram...

CGTalk Moderation
10-14-2006, 10:27 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.