View Full Version : simple group selection question

11 November 2006, 02:36 AM
Once I select a plane, I'm using the following to aim the plane at the camera...

select -af perp ;
aimConstraint -offset 0 1.55 0 -weight 1 -aimVector 1 0 0 -upVector 0 1 0 -worldUpType "vector" -worldUpVector 0 1 0;

... but the plane is one of 8 planes that need to be aimed. I'd like to select the group node above all 8.

it's gotta be easy, yeah? i'm a noob.

11 November 2006, 07:45 AM
That kind of thing is very easy. I'll walk you through it.

global proc aimSelectedAtCamera() {//first we'll declare the procedure that contains the code to aim our selection at the camera
//here we are declaring a string array that will contain our selection
//we are assigning the filterExpand command to the $objs variable
//the filterExpand command filters the current selection for whatever type of object or element we want
//since we are using the -sm 12 flag filterExpand returns all of the polygonal objects we have selected
//anything that is a part of the selection that is not a polygonal object will be ignored
//this way you can select the planes you want to point at the camera, or a group containing the planes, or whatever
//it doesn't matter as long as your planes are part of the current selection
string $objs[] = `filterExpand -sm 12`;
//here we are assigning the current panel to a variable called $activePanel
//the reason I'm doing this will become clear in a little bit
string $activePanel = `getPanel -withFocus`;
//I'm declaring a string called $activeCamera
string $activeCamera;
//this chunk of code makes sure that something is actually selected
//if nothing is selected you'll get an error message
if(size($objs) == 0)
//we could assign an aimConstraint to the objects in our selection and have them point to an object called persp but this could cause problems
//you might want to have the selection point to a camera other than persp
//or if you have been renaming your cameras you might not have one called persp
//so what this following chunk of code does is find the camera assigned to the current panel and we will use that camera to constrain our objects
if(`getPanel -typeOf $activePanel` == "modelPanel") { //this checks to see if the current panel is a viewport.
$activeCamera = `modelPanel -q -camera $activePanel`; //if the current panel is a viewport this command finds the camera that the viewport is using
else {
error("NO VIEWPORT SELECTED"); //if the current panel isn't a viewport and is something like the attribute editor or hypergraph you'll get an error
//now that we have the active camera we can use it as an aimConstraint for the objects in our selection
//we'll have a loop that goes through the $objs array and assignes an aimConstrint to every object in that array
for($obj in $objs) {
//constrains the current object in the loop to the active camera
aimConstraint -offset 0 1.55 0 -weight 1 -aimVector 1 0 0 -upVector 0 1 0 -worldUpType "vector" -worldUpVector 0 1 0 $activeCamera $obj;
}//close the procedure and there you have it
//select your planes make sure that you are in your perspective view and run the aimSelectedAtCamera command

If you have any questions don't be afraid to ask.

11 November 2006, 06:24 AM
wow man, thanks a million! it does look relatively simple. I can't get it to work yet. returns YOU HAVE NO POLYGONAL OBJECTS SELECTED even when I do. will have to do some research.

anyway, thanks! :)

12 December 2006, 03:11 AM
hmm don't know what to tell you, other than it works for me. Make sure you're selecting polygonal objects and not polygonal elements. That is make sure you're selecting the plane object and not the faces in the plane.

If you keep having trouble try swapping the line:

string $objs[] = `filterExpand -sm 12`;

with this line:

string $objs[] = `ls -sl`;

that might work better for ya.

CGTalk Moderation
12 December 2006, 03:11 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.