aim multiple objects

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  05 May 2011
aim multiple objects

Ok, probably a really stupid question.

Aim constraints work by selecting a target object (say a locator) and then the object to aim (eyeball). Easy.

But what if I want dozens or hundreds of objects to aim at that locator. The aim works by the order of two objects being selected. Am I missing something?

I've also looked on creative crash without any luck.

Thanks in advance...
 
  05 May 2011
Wooosh... After an hour and a half of tedious research and trying... I created a script that will do this XD. I'm interested in learning mel and python, so thought I'd take a crack at this, even though I know nothing about mel XD. My main hassle was getting a loop working for this aimConstraint command. For all loop examples I could find for things, it kept wanting to stop after the first constrain, unlike say a delete command using the same loop codes I saw..

//Multiple Aim Constraint MEL script, v0.1, by Mitch Zais
 //Replace "target" with the name of your target object
 //Select all objects you want to aim constrain to the target and execute the script
 
 $aimTarget = "target";
 string $selection[] = `ls -sl -l`;
 for ( $each in $selection ) {
 aimConstraint $aimTarget $each;
 }


I'll probably turn this into a little project of mine for learning MEL. Give it a GUI, make it so you can just select the target also, and branch it out to other constrains.


Last edited by Kakkoii : 05 May 2011 at 12:05 AM.
 
  05 May 2011
Cool little script me likey!
__________________
Showreel
 
  05 May 2011
MEL is really powerful in these tedious tasks.. i suggest learning it, it will help you tremendously while animating or even modeling, let alone rigging...

the script could be further optimized to dont have to replace the 'target' that you have to input manually... for instance let it be selected first, then you could just extract the $array[0] from the for loop, and make it the object to aim at. that way, the user would select the driver, then the hundred of drivens, and then just click on the shelf.

something like


$sel = `ls -sl -fl`;
for ( $each in $sel ) {
if($each != $sel[0]){
aimConstraint $sel[0] $each;
}
}


think this should work, im just thinking out loud here..

btw, good job on the script, and go on with learning MEL :)
__________________
----- nothing is true. everything is permitted. -----
..... there are no rules, just tools
 
  05 May 2011
if you want to have the planes face the first selected object, make the aimconstaint code into:

$sel = `ls -sl -fl`;
for ( $each in $sel ) {
if($each != $sel[0]){
aimConstraint  -offset 0 0 0 -weight 1 -aimVector 0 1 0 -upVector 1 1 0 -worldUpType "vector" -worldUpVector 0 1 0 $sel[0] $each;
}
}


I use this for making studio light reflectors and material light planes. I've been meaning to make my script work with multiple selected objects so thanks for bringing this up.
 
  05 May 2011
that's the same as what i wrote, just with the additional gibberish :P
(if the gibberish aint there, it takes the settings you currently have in your option box for the given constraint / command )
__________________
----- nothing is true. everything is permitted. -----
..... there are no rules, just tools
 
  05 May 2011
I know - I thought it was obvious I just took your code and added the stuff to force the planes to face your target.
 
  05 May 2011
Wow, thanks for the help everybody. One of the reminders of why I love Maya. I'll give your solutions a shot and let you know how it goes.
 
  05 May 2011
Originally Posted by nemeru: that's the same as what i wrote, just with the additional gibberish :P
(if the gibberish aint there, it takes the settings you currently have in your option box for the given constraint / command )


well it's not any "gibberish" at all, because you don't know what other people's default setting look like, so forcing the arguments are necessary in most cases.
__________________
http://www.brainyart.me
 
  05 May 2011
Yeah it's a total embarassment that I don't know mel. On one hand I know Maya inside and out as a generalist, but i've just been lucky that anything requiring "out of the box" scripting was already done by you wonderful people, or there was another solution.

To me it's like Spanish, I can read and maybe edit it if there's enough context, but I can't write from scratch.

Any suggestions on how a complete scripting novice would get started? Is there such a thing as "Mel for Dummies?" I ask because most resources I find start from the assumption you know some programming already.
 
  05 May 2011
the best book on MEL in my opinion is MEL Scripting for Maya Animators. The thing about MEL syntax is that it looks just like most Unix/C apps. You have a command at the start and arguments, usually with a -flag (render -r mr -s 1 -e 200 etc. is the same as ncftp -u ftp.site.com). You could learn how to do shell scripting in OS X or Linux and it would tell you just as much about MEL syntax, basically. That's very different from Python, which is object oriented.

take this MEL example:

string $mySelection[] = `ls -sl`;
print $mySelection;

in an OS X bash shell script, you can get the contents of the pasteboard and assign it to a variable like this:

pbcontents=`pbpaste`;
open $pbpaste

that does this:

http://www.vimeo.com/15056992

The only difference are the commands that each environment comes with and a bit of syntax differences (C doesn't have the $ in variables until it's being called as a variable, not in the assignment). If you want to learn MEL, I suggest getting a good basics of C or Unix shell scripting book and that way, you can learn the syntax but you also learn to write things that can mix both system commands and MEL:

global proc GoP()
{
if (!(`pluginInfo -q -l objExport`))
	{
		loadPlugin objExport;
	}
	
$timestamper = `date -format YYYYYYMMDDhhmmss`;
string $mySelection[] = `ls -sl`;

if( `about -win`)
	{
	system ((("md %TEMP%") + "\\") + $timestamper);
	file -force -options "(groups=1;ptgroups=1;materials=1;smoothing=1;norma  ls=1" 
	 -typ "OBJexport" -pr 
	 -es ((("%TEMP%/" + $timestamper + "/") + $mySelection[0]) + ".obj");
	system ((("%TEMP%" + "\\") + $timestamper + "\\") + $mySelection[0] + ".obj"); 
	}
else
	{
	system (("mkdir /tmp/") + $timestamper);
	file -force -options "(groups=1;ptgroups=1;materials=1;smoothing=1;norma  ls=1" 
	 -typ "OBJexport" -pr 
	 -es ((("/tmp/" + $timestamper + "/") + $mySelection[0]) + ".obj");
	system ((("open /tmp/") + $timestamper + "/") + $mySelection[0] + ".obj");
	}
}


That was one of the first MEL scripts I wrote and it sends textured obj meshes to Photoshop and then opens it with system commands. The most complicated thing about it is the escape characters and variables, which you'd best learn from a C book. If you want to learn C and Unix scripting, these two books have been great in helping me learn:

A Practical Guide to Unix for Mac OS X Users by Mark Sobell

and

Programming in C by Stephen Kochan

You can learn Unix from Linux books but OS X has many specific commands like open and pbpaste and I think you're a Mac user, so that's why I suggest it. Combining those with MEL Scripting for Maya Animators will make things a lot clearer than if you were just learning MEL alone, since I think the book assumes you know what C syntax looks like.

Last edited by cgbeige : 05 May 2011 at 04:57 AM.
 
  05 May 2011
Thanks for the tips Petr and Dave. One of my test loops used a similar method, but I couldn't quite get it working the way I wanted because I didn't think the selection process worked like that. I always thought it was defined by the white wireframe objects being the aims, and the green primary selection being the target, with order in the outliner determining selection order on a secondary level. But I think the primary reason it was never working for me is that I wasn't using $each as the aim objects, because I had thought that the 'for ($each in $sel)' would make it execute the aimConstraint for each object in the selection instead of all at once. But it would only do it for the first, noob mistake.

So thanks for the help with that, definite improvment. Although for this script I want to develop, I want to figure out a way that you can just select your aim objects first, execute the script and then have it ask you to choose the target, to make it as user friendly as possible. Somehow having the previous selection stored in some sort of temporary variable thats value is obviously only there for the duration of the script process. And that variable then able to be used as the aim objects on the aimConstraint line, along with the current selection $sel being the target.

Last edited by Kakkoii : 05 May 2011 at 08:28 AM.
 
  05 May 2011
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 01:08 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.