View Full Version : How to query a constraint's target list without knowing the constraint type?

04 April 2009, 05:34 PM
I posted this question on today, but figured I'd increase my attack surface by reposting here as well. Feel free to answer on StackOverflow and get some additional reputation points if you're a member.

In Maya, I have a list of constraints gathered by the following code. I want to iterate the constraints and query the targets for each of them:

cons = ls(type='constraint')
for con in cons:
targets = constraint(query=True, targetList=True)

The problem, there is no general constraint command for manipulating all constraints. Instead, each constraint has its own unique MEL command associated with it.

Is there any way to query the targets on a constraint without having to type check each constraint and tediously run its respective MEL command?

04 April 2009, 06:47 PM
listConnections on the .target attr?
the cleanup in mel:

string $cons[] = `ls -type "constraint"`;
for ( $con in $cons ){
string $targetAttrString = ( $con+ ".target" );
string $connections[] = `listConnections $targetAttrString`;
string $connectionsFlattened[] = stringArrayRemoveDuplicates($connections);
for ( $f in $connectionsFlattened )
if ( $f != $con )
print ( $f+ " is a target\n" );

CGTalk Moderation
04 April 2009, 06:47 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.