FORUMS: list search recent posts

Expressions linked to "this" property instead of specific?

COW Forums : Autodesk Maya

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Robert Morris
Expressions linked to "this" property instead of specific?
on Sep 9, 2009 at 4:39:07 pm

Hello. I'm not a newbie to Maya, but fairly new to expressions in Maya. I was wondering if there was a way to link an expression to a "this object" property instead of a specific object. For example, say I have a texture node on a material that I want to apply to several different objects. The expression:

place2dTexture1.repeatU = Plane1.scaleX;
place2dTexture2.repeatU = Plane2.scaleX;

This would give me a result for a specific object. But if I have the material applied to different objects, they would all respond to the scale of one object. What I would like to do is:

place2dTexture1.repeatU = thisObject.scaleX;

So that the material can be applied to different objects with different scales, and still repeat at the same size in relation to the object each instance of the material is applied to. Is this possible?


Fine Art Drawings | Photography | Compositing | VFX | Titles | Keying | 3D


Return to posts index

Alvaro Castaneda
Re: Expressions linked to "this" property instead of specific?
on Sep 9, 2009 at 6:08:00 pm

Hi

You can do that like this


//get selected objects to an array
$allObj = `ls -sl`;

// get the number of objects selected
$len = size($allObj);

//Loop trought the objects
for ($i=0; $i < $len; $i++)

{
//connect root rotateX to all selected objects
connectAttr -f root.rotateX ($allObj[$i] + ".rotateX");
}
print "All objects hooked";


you can just modify the connectAttr objects and parameters to what ever you want

----------------------
varomix - pixelEater
http://www.intelianimate.com


Return to posts index

Robert Morris
Re: Expressions linked to "this" property instead of specific?
on Sep 9, 2009 at 6:40:12 pm

Thanks... this gives me something to play with. But couldn't I just simply link to the "root" then using my original expression? Like this:

place2dTexture1.repeatU = root.scaleX;


Fine Art Drawings | Photography | Compositing | VFX | Titles | Keying | 3D


Return to posts index


Alvaro Castaneda
Re: Expressions linked to "this" property instead of specific?
on Sep 9, 2009 at 7:01:38 pm

you can, but you have to manually do it for each object

----------------------
varomix - pixelEater
http://www.intelianimate.com


Return to posts index

Robert Morris
Re: Expressions linked to "this" property instead of specific?
on Sep 9, 2009 at 7:13:19 pm

I tried using "root.scaleX" and it says the expression is invalid. What am I doing wrong?

My objects are all named differently, so I don't know that your array will work. What I want is that ANY object I apply this material to, it reacts to the scale of that individual object.


Fine Art Drawings | Photography | Compositing | VFX | Titles | Keying | 3D


Return to posts index

Alvaro Castaneda
Re: Expressions linked to "this" property instead of specific?
on Sep 9, 2009 at 7:19:24 pm

root is not a special word in maya there's an object called root in my scene, if you object is called null one use that
null1.rotateX

in your case you want to connect this
place2dTexture1.repeatU = Plane1.scaleX;

that could be

connectAttr -f place2dTexture1.repeatU ($allObj[$i] + ".scaleX");

so the full code would be this


//get selected objects to an array
$allObj = `ls -sl`;

// get the number of objects selected
$len = size($allObj);

//Loop trought the objects
for ($i=0; $i < $len; $i++)

{
//connect root rotateX to all selected objects
connectAttr -f place2dTexture1.repeatU ($allObj[$i] + ".scaleX");
}
print "All objects hooked";






select all the planes you wanna connect first, then run the code

----------------------
varomix - pixelEater
http://www.intelianimate.com


Return to posts index


Robert Morris
Re: Expressions linked to "this" property instead of specific?
on Sep 9, 2009 at 7:32:43 pm

Okay, this is now making more sense. Thank you for taking the time to explain.

One thing that is still not clear... when you say "//get selected objects to an array", what do you mean by "selected" objects? I want this expression to run on any object that has this material applied to it... whether they are selected or not. Instead, wouldn't I want to "ls" all the objects with this material, instead of using the "-sl" flag that applies to (I'm assuming) selected objects. Like I said, I'm new with what these expression commands and MEL scripting means. But I'm trying to learn.


Fine Art Drawings | Photography | Compositing | VFX | Titles | Keying | 3D


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]