PDA

View Full Version : Decide if object is "normal" or a reference?


dandruff
04-24-2009, 02:31 PM
I'm working on a part of a script that needs to take a number of selected models and then replace them with other models. The problem is that I need to know if they are references or not. Is there any way to get that info from a selected object?

Another thing I would like help with... what is the easiest way to remove a reference from a scene from mel/python?

Thanks in advance

.d

Keilun
04-24-2009, 06:08 PM
I can't think of an easy way of doing this purely in MEL. It is possible to create a MEL command in the API that can do this really easily. Specifically you could make a command named:

isFromReferencedFile <objName>

Which in it's doIt() method initializes MFnDependencyNode to the object and subsequently calls MFnDependencyNode::isFromReferencedFile(). This is probably easily doable in Python as well.

berniebernie
04-24-2009, 06:18 PM
string $allrefs[] = `file -q -r`;
//
string $sel[] = `ls -sl`;
referenceQuery -f $sel[0];


I haven't tried any of those, look around http://mayamel.tiddlyspot.com/

Keilun
04-24-2009, 06:28 PM
string $allrefs[] = `file -q -r`;

This returns all reference files in the scene.

string $sel[] = `ls -sl`;
referenceQuery -f $sel[0];

This queries the reference file name for a given reference node.

Speaking of which that reminds me that you also asked about removing references from a scene. You can either remove or unload using the file command. You can use the first code sample up top `file -q -r` to query all the files in the scene. Pick the one you want, and then subsequently call `file -rr <refFile>` or `file -ur <refFile>` to remove/unload the file.

Note that, it's an all or nothing thing here. You cannot selectively remove only a single object from a referenced file.

r4inm4ker
04-25-2009, 02:22 AM
to test whether the selected object is a reference or not :


referenceQuery -isNodeReferenced $object;

dandruff
04-27-2009, 07:32 AM
Thank you all, it works like a charm!
(python)


selection = cmds.ls(sl = True)
for model in selection:
refcheck = cmds.referenceQuery(model, inr = True)
if (refcheck == 1):
reftodel = cmds.referenceQuery(model, f = True)
cmds.file(reftodel, rr = True)
cmds.file(newfile, r=True)
else:
cmds.delete(model)
cmds.file(newfile, i=True)

CGTalk Moderation
04-27-2009, 07:32 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.