On 24/10/2016 at 07:43, xxxxxxxx wrote:
Hi Riccardo,
Thanks for the help.
Using your code and the example file provided. Add one simple User Data item to the cube.
Something simple like a float slider is enough.
Then use the Set Driver/Set Driven options to create an xpresso tag that has nodes that connect the host object with that tag to drive the UD slider.
Then please try your code again and see what happens.
When I do this. The Object node in xpresso ends up being empty and broken (yellow colored header).
It looks like there's a bug with handling UserData in the CopyTo() function. Or maybe it's not yet supported in the SDK?
If xpresso was supported Melange SDK like it is in the C4D SDK. I could go in there and set the object link to the host object manually. But of course it would be better if the CopyTo() function copied the UD automatically.
-ScottA
*Edit
Here is an example with the copy User Data code in it.
The problem is that on the new object inside of the new document. The "Object" xpresso node is empty and broken (yellow).
I don't know if this happening from a bug, or UD not being supported, or if the way I'm copying the User Data from the source object to the target object is wrong?
int main(int argc, Char* argv[])
{
// Path to the scene to scan.
const String file = "C:\\Users\\user\\Desktop\\source.c4d";
//Load the scene document
BaseDocument *c4dDoc = LoadDocument(file, SCENEFILTER_OBJECTS);
if (!c4dDoc) return -1;
//Load the first object in the scene
BaseObject *currentObj = c4dDoc->GetFirstObject();
if (nullptr == currentObj) return -1;
//Get the User Data on the source object
DynamicDescription *sourceUD = nullptr;
sourceUD = currentObj->GetDynamicDescription();
//Retrieve the Xpresso node tag on the source object
BaseTag *xTagSource = currentObj->GetTag(Texpresso);
if (nullptr == xTagSource) return -1;
//Create a new object
BaseObject *newObj = BaseObject::Alloc(Osphere);
if (nullptr == newObj) return -1;
//Copy the UserData from the source object to the target object
DynamicDescription *targetUD = newObj->GetDynamicDescription();
sourceUD->CopyTo(targetUD);
//Create a new Xpresso tag on the new object
BaseTag *xTagTarget = newObj->MakeTag(Texpresso);
if (nullptr == xTagTarget)
{
BaseObject::Free(newObj);
return -1;
}
//Copy the source tag's data to the new one
xTagSource->CopyTo(xTagTarget, COPYFLAGS_0, nullptr);
//Insert the newly created object
c4dDoc->InsertObject(newObj, nullptr, currentObj);
//Remove the source object from the scene
currentObj->Remove();
BaseObject::Free(currentObj);
currentObj = nullptr;
//Save the scene with both object on file.
SaveDocument(c4dDoc, "C:\\Users\\user\\Desktop\\dest.c4d", SAVEDOCUMENTFLAGS_0);
return 0;
}