PDA

View Full Version : API: copy objects for one scene to another


MasterZ
04-10-2006, 09:11 AM
While using the Maya 7 API...
I would like to be able to open two files? or if you have to one at a time.
And then copy an object(s) and all it's settings to the other file.

This is basically for steamlining a multi shot production.

Ya I can open an ASCII file and cut and paste or even write a none API to do that automatically but really I am looking to learn something about the API (which clearly should have advantages).

Again...
I want to open a template scene file, and store particular objects and then open the target scene file and drop in the objects.

Since MObjects are pointers I need to duplicate the objects and stores them so they survive closing the scene file (seems to be the only way no multiple files open at once? was the standard for document apps at one point?), which will likely free the objects MObject points to.

Any ideas what to do?

Robert Bateman
04-10-2006, 12:53 PM
no there is no way to open multiple files, basically you can do what you want by importing a file (or by using references). The API has benefits, but you are fairly restricted in the way you can work. Opening 2 files would be an example of something that would be nice, but not supported....

MasterZ
04-10-2006, 09:30 PM
I figured so your saying there is no way to temporarily store an entire node from one file, close it, open a new file at create that node either, without extracting all attributes and values and storing them in a dictionary or something, [via other post info - thanks - MFnDependencyNode::attributeCount() and MFnDependencyNode::attribute() To get the actual values from the attributes, you'll need to use the higher derived function sets (MFnNumericAttribute, MFnMatrixAttribute etc) - sounds overly complicated for this purpose].

Any ideas? Samples/links even?

I looked via the GUI - "Export selection" but it seemed to include all the linkage etc. and was not per node as expected = too much basically unusable / undesirable.

Robert Bateman
04-11-2006, 10:09 AM
I figured so your saying there is no way to temporarily store an entire node from one file, close it, open a new file at create that node either, without extracting all attributes and values and storing them in a dictionary or something,

correct.


Any ideas? Samples/links even?



MItDependencyNodes it(MFn::kInvalid);
for( ; !it.isDone(); it.next() )
{
MFnDependencyNode fn( it.item() );
std::cout << fn.name().asChar() << std::endl;
unsigned numAttrs = fn.attributeCount();
for( unsigned i=0; i!= numAttrs; ++i )
{
MObject oAttr = fn.attribute(i);
MFnAttribute fnAttr(oAttr);
std::cout << " " << fnAttr.name().asChar();
std::cout << " " << oAttr.apiTypeStr() << std::endl;
}
}

thematt
04-12-2006, 10:34 AM
did you know that "ctrl c" "ctrl v" can do just that.Although it paste it with "Pasted_" tag in front.
It can be usefull.

cheers

MasterZ
04-18-2006, 11:10 PM
[thematt, Copy and Paste don't apply to Developing with the API.]

{I just posted to the previous message about VS 2005 with Maya API problem which kept me from working on this problem for a few weeks.}

!!! I am amazed at how this code works, thanks Robert.

Now I really just want to see Dependencies for a node with a certain "name", and I am just pondering how that is suppose to happen.

I see you can filter Types, which is not refined enough. I am looking at the OBSOLETE method for getting the "item", which I think is what you would query here.
Really we want to see dependencies of a particular selection (for which I have this)...
MSelectionList list;
MDagPath node;
MObject component;
MFnDagNode nodeFn;
MStatus stat;

MGlobal::selectByName(nodeName, MGlobal::kAddToList);
MGlobal::getActiveSelectionList(list);
for(index = 0; index < list.length(); index++) {
list.getDagPath(index, node, component);
nodeFn.setObject(node);
cout << nodeFn.fullPathName().asChar() << " is selected" << endl;

So I'm also looking around for documentation on your method...
MFnDependencyNode fn(it.item());
the fn() is knd of hard thing to search for, I suppose it should be obvious but at this point the learning curve is really freaking me out.

Lets review I want to simple copy nodes from one scene to another, we have to try and store all dependency nodes and their values for certain nodes, beyond the life of a scene (to another one).

Just trying to isolate a way to select certain dep-nodes related to particular items and/or branches seems to be needed.
Preferable from a selection list selected by name with only one item/object/node at a time one should be able to store the names and values for it to be use to restore a newly created node in another file.

CGTalk Moderation
04-18-2006, 11:10 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.