PDA

View Full Version : returning all child references


djtomservo
11-29-2006, 11:34 PM
Hi all, is there a way to get all reference nodes associated with a given reference node other than having some sort of recursive proc? referenceQuery -n seems to only return reference nodes that are immediate child references of the passed node, but sadly there doesn't seem to be a way to get grandchild references.

Alternately, is there a way to make the import reference function import descendent references? Calling either file -ir -rfn or just file -ir don't seem to only import objects from the specified reference. . .would be super handy if you could optionally import the top node and its grandchildren (without having to go all crazy recursive). Thanks in advance.

djtomservo
11-30-2006, 12:54 AM
. . .should you ever find yourself in a situation where you need to do this sort of thing:


string $refNodes[] = {};
string $top = "ref_primsRN"; //or whatever the node you want to find the associaton for, this has to be a top level node or it'll probably choke

string $references[] = `ls -typ reference`;
for( $ref in $references )
{
if( catchQuiet( `referenceQuery -rfn $ref` ) )
{
warning("invalid reference node.\n");
}

else
{
if( `referenceQuery -rfn -tr $ref` == $top )
{
$refNodes[ size( $refNodes) ] = $ref;
}
}
}

grantimus
11-30-2006, 02:58 AM
That is some nice code djtomservo, really it is ......but so is this `listRelatives -allDescendents`.........

djtomservo
11-30-2006, 03:06 AM
That is some nice code djtomservo, really it is ......but so is this `listRelatives -allDescendents`.........

considering that listRelatives -ad doesn't give you back child reference nodes makes the code all the nicer. . .try it, not on nodes that the reference refers to but on the actual reference nodes, ie the things that usually end in RN. you will get back. . .well, nothing.

grantimus
11-30-2006, 03:16 AM
ok you're right, I thought you where looking for all the children of just some node in general. Guess I should have read a little more carefully, my mind has trouble when cafine is the only thing keeping me awake.

tymznd
05-16-2007, 04:05 PM
Here is the error I get when running this script

// Error: Reference node 'zz:sharedReferenceNode' is not associated with a reference file. //
// Warning: invalid reference node.
//

djtomservo
05-16-2007, 04:55 PM
yeah those sharedReferenceNodes are annoying. . .actually over the past few weeks i've been using this instead. This one may be a bit faster since it doesn't check every reference in the scene (yes, i broke down and went all crazy recursive):


global proc string[] LT_dfCTRefsFromTop( string $refNode )
{
string $nodesInRef[] = `referenceQuery -n $refNode`;
string $refNodes[] = {};
for( $node in $nodesInRef )
{
if( `nodeType $node` == "reference" )
{
if( !catchQuiet( `referenceQuery -f $node` ) )
{
$refNodes[ size( $refNodes ) ] = $node;
if( size( `LT_dfCTRefsFromTop $node` ) )
{
string $moreRefs[] = `LT_dfCTRefsFromTop $node`;
$refNodes = stringArrayCatenate( $moreRefs, $refNodes );
}
}
}
}

$refNodes[ size( $refNodes ) ] = $refNode;
$refNodes = stringArrayRemoveDuplicates( $refNodes );
return $refNodes;
}


this one will still throw the error on reference nodes that aren't associated with a file (ie sharedReferenceNodes), but the catchQuiet keeps it running.

In theory you could then flip the returned array or start at the bottom of it and import from each reference in order and not have to worry about checking for parents, which is why i was originally trying to solve this problem. That's in theory, i haven't tried that approach yet, usually when it comes time to import i check each reference for a parent reference before importing and import based on that result.

CGTalk Moderation
05-16-2007, 04:55 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.