View Full Version : mel accessing group-specific object
05-28-2012, 04:02 AM
i have a bunch of objects with the same name, but they are in different groups. i have a script that needs to be able to find that object within a specific group. but the script doesn't work because it's seeing all objects in project, and it's confused as to which object i want it to find. (if i remove all but one the script finds it and runs. otherwise i get the error: setAttr: Error reading data element number 1: )
i can't give the objects unique names. the script is looking for a specific name. it just needs to know the scope of where to look.
i have two ideas but don't know how to write either one.
1) provide scope. how could i tell a function to look in a specific group of objects only, so to avoid other objects with the same name?
setAttr persp.tx `getAttr myGroup1.CamSpot1.tx`;
where myGroup1 is the scope. but that doesn't work, it thinks that's the object's full name.
2) how could i re-write this code to actually work:
setAttr persp.tx `getAttr "myObj"3.tx`;
where "myObj" is a string variable that can be changed elsewhere in the script. example:
myObj = "camSpot"
so getAttr now gets a value from camSpot3.tx
05-28-2012, 09:23 AM
don't get confused between scope and (dag) path. you use a . (period) to delimit nodes and attributes, and a | (pipe) to delimit dag paths, as shown when you do an `ls -sl -long` and you see the full (long) path names.
setAttr persp.tx `getAttr "myGroup1|CamSpot1.tx"`;
string catenation is what you need for 2)
string $myObj = "camSpot";
setAttr persp.tx `getAttr ($myObj + "3.tx")`;
it's good practice to always surround your literal strings in " double-quotes so you know what's what.
05-28-2012, 01:51 PM
thanks NaughtyNathan! that's just what i was looking for. yeah i'm still learning this language syntax and all. but i did test and it's working now. thankya!
05-28-2012, 01:51 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.