c4DAtom::CopyTo() and AliasTrans
-
On 26/09/2013 at 06:34, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 13.061
Platform: Windows ;
Language(s) : C++ ;---------
Hello,
I like to copy some objects from one c4d project into another project. I open a second project with LoadDocument(...) and now I can scan all objects. I'm create new objects in my project and use the CopyTo(..) function to copy all data (BaseContainer and tags) to my object in my project. That's working.
But in some BaseContainers are LINKs inside with references to other objects. The CopyTo(..) function can not copy this links simple. I'm reading something about the AliasTrans parameter, but I don't understand how this is working. Or what I have to implement it. How convert C4D the links into my project?
regards
Markus -
On 26/09/2013 at 09:34, xxxxxxxx wrote:
Allocate (AutoAlloc will work) an AliasTrans and include it in the CopyTo. This class is then tasked by the call to 'fix' the links. The docs for AliasTrans provide an example:
AutoAlloc<AliasTrans> aliastrans; if (!aliastrans || !aliastrans->Init(document)) return FALSE; dup = op->GetClone(COPYFLAGS_0, aliastrans); if (!dup) return FALSE; aliastrans->Translate(TRUE);
-
On 26/09/2013 at 22:29, xxxxxxxx wrote:
Does it means, I have to implement the Translate() function itself?
Because if I added this code, nothing happend with the links. All links in BaseContainer are empty. !Cry
[URL-REMOVED]
I add a part of my code: (it's only a clip)
...
BaseDocument* pXrefDoc = LoadDocument(file, SCENEFILTER_OBJECTS | SCENEFILTER_MATERIALS, NULL);
BaseObject *pobj = pxrefdoc->GetFirstObject();
AutoAlloc<AliasTrans> aliastrans;
if (!aliastrans || !aliastrans->Init(pdoc)) return;
while ( pXrefobj ) {
C4DAtom * atom;
BaseObject* poNew;
//if (!pXrefobj->CopyTo( poNew, COPYFLAGS_0, aliastrans )) return; // copy base container data and tags, but no links
atom = pXrefobj->GetClone( COPYFLAGS_0, aliastrans );
if (!atom) return;
aliastrans->Translate( TRUE );
poNew = (BaseObject* )atom;
poNew->SetName( "My::"+ pXrefobj->GetName()); // set name with namespace
pdoc->InsertObject( poNew, NULL, ppred );
pXrefobj = pXrefobj->GetNext();
}
...
[URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.
-
On 27/09/2013 at 00:26, xxxxxxxx wrote:
You probably need to postpone the aliastrans->Translate() call until after the loop so that all of the objects that are linked exist in (have been inserted into) the document for translation. If one AliasTrans fails, you might need an array of them (one for each clone).