Hey.
Does anyone know how to set up a control object, that when selected, selects other objects in my scene?
I'm thinking script job, but I've never really used them before, and I can't seem to find the correct condition for it to work.....
Any ideas?
I first tried to just put all the selection handles in one place, but even if I selected all the handles it would only select the top node in the hierarchy. So that didn't work....
Replies
If that condition is passed, then you can just call all the script required to select the objects needed.
This seems pretty inflexible to me though, you'd have to keep editing the script called by the scriptJob if you wanted to add or remove items from the select group (or if you needed to change the name of the "master node").
That's the first method that springs to my mind anyway.
It might be possible to use some sort of scriptNode connected to the "master select node"? Not sure what the evaluate options are for those, though, you might not be able to have them activate on select.
How do you manage script jobs anyways, are they loaded with the scene? Or do you have to start them manually every time?
What do you wish to accomplish with this? Because there might be other ways of accomplishing the same end product.
Whargoul's idea is a solid improvement though, a more generic scriptJob that queries a specific custom attribute is much more flexible than a hard-coded one, and allows multiple of these "master control" objects to be used without writing more than one script.
You could even do something like instead of having a string attribute, just have a compound string array attribute that you can hook up any node's "message" output plug into, that way it doesn't matter if the node name changes, it will still be connected. The scriptJob would simply select all nodes with their .message attribute plugged into your custom attribute.
That might be more flexible than manually filling in a string with object names.
If you want it to be something that will work on anyone's install of Maya then you'd probably need to set up a scriptNode on your scene that gets run on "scene opened" which launches the scriptjob to watch for the attribute on selection change, and another script node that kills this scriptJob when the scene is closed or a new scene is opened.
That way nobody needs to install custom scripts to make it work, it'd all be self-contained in the scene.
Or use Quick Select Sets...
Quick select sets is probably easiest, and what I have used in the past, but you don't end up with an object to select.
You select what you want to be added to the selection group, then run the script. To reselect, make sure you don't have anything else selected and run the script. If you want to make a new selection group, select anything and run the script. It will toss out your first group and you can move forward with your new selection group.
Let me know if this is what you had in mind.
string $selectionGroup[];
string $currentSelection[];
$currentSelection = `ls -sl`;
//see if there's anything already in selectionGroup
int $sizeSelectionGroup = size($selectionGroup);
//see it there's anything selected
int $sizeCurrentSelection = size($currentSelection);
//if it's empty but nothing is selected prompt user to select items for the group
if (($sizeSelectionGroup == 0) && ($sizeCurrentSelection == 0))
{
warning "Please select objects to add to selection group";
}
//if it's empty, add the selected items
if (($sizeSelectionGroup == 0) && ($sizeCurrentSelection != 0))
{
$selectionGroup = `ls -sl`;
}
//if it has stuff in it, but nothing is selected, select the items in it
else if (($sizeSelectionGroup != 0) && ($sizeCurrentSelection == 0))
{
select $selectionGroup;
}
//if it has stuff in it, but something else is selected, clear it an add the new stuff
else if (($sizeSelectionGroup != 0) && ($sizeCurrentSelection != 0))
{
$selectionGroup = `ls -sl`;
};
I'm working on a script now. I've got a solid plan I think, but I've been proven wrong before :P
How do I create a scriptnode that contains a larger amount of code?
I need to create a scriptnode (with MEL) that contains my global procedure, but the syntax gets broken if I try to add it all in to the scriptnode command....
Or is there another solution? I want my scriptnode (that runs on scene open) to create the global procedure used by my scriptjob.....
Did anyone understand a word of that :P
If use this command: It will select both objects (pSphere1 and pSphere2)
If I store it as a value in a string and try to use it with the select command:
I will get this: // Error: line 1: No object matches name: pSphere1 pSphere2 //
How do I solve this the best way? Any ideas?
EDIT: The code tag wont allow me to type "$objects", had to add a blankspace. Ofcourse I would not use that in my script.
I think this may help:
http://accad.osu.edu/~aprice/courses/694/variables.html#array
Yeah I guess I'll have to do something like that... This seems to work:
string $objects = "pSphere1 pSphere2";
string $selArray[];
$selArray = stringToStringArray($objects, " ");
select -cl;
for ($i=0; $i < size($selArray); $i++)
{
select -add $selArray[$i];
};
Anyone knows how to check if a specific scriptnode exists? (using MEL)
string $objects = "pSphere1 pSphere2";
string $select = "select " + $objects;
eval $select;
Seems a bit easier
You can get the script here: http://www.igorbazooka.com/createSelector.mel
This is how you use it:
- First select the control-object.
- Then select any number of objects that you want it to select.
- Run the script.
- When the control-object is selected, it will select the other objects instead.
- NOTE! You have to deselect everything before selecting the control-object.
(Apparently "SomethingSelected" will not evalute when the selection changes, only when you go from nothing selected to something selected..... Didn't find any solution to this.)
- If the scene is saved the script control-objects will work when the scene is loaded again.
Thanks for the help guys!
Maybe someone will find this little script usefull
But mostly I used it as an excuse to practice on my scripting :P
Arbitrary Mesh
-Group
--Obj1
--Obj2
--Obj3
"How do I devise a setup whereby when I select one object, Maya automatically selects another object?"