I'm currently trying to figure out, what's going on in the following code.
Given the following situation: I have two objects in my document. 1 Cube Primitive and an instance pointing to that cube.
Now I simply want to swap them. I'm fetching the instance link so I get access to the cube.
My current code looks like this, it is executed inside a CommandData
BaseObject* instance = doc->GetActiveObject(); GeData data; if (!instance->GetParameter(DescID(INSTANCEOBJECT_LINK), data, DESCFLAGS_GET::NONE)) return nullptr; const auto refObj = static_cast<BaseObject*>(data.GetLinkAtom(doc, Obase)); // Temporary insertion points BaseObject* refUp = refObj->GetUp(); BaseObject* refPred = refObj->GetPred(); // Remove the reference object and move it to the instances place refObj->Remove(); doc->InsertObject(refObj, instance->GetUp(), instance->GetPred()); // Remove the instance object and move it to the reference object's place instance->Remove(); doc->InsertObject(instance, refUp, refPred);
With his code, however, the result is somewhat weird.
You can see what happens, if you create the following scene:
- Create a cube
- Create an instance from that cube
- Make sure, the instance is placed topmost in OM
- Run this code, the ref object (Cube) will be removed.
So what am I missing here?
refPred points to the instance itself, which is wrong, imho. Any push in the right direction would be great!
Maybe there's some concepts available how to swap object in a OM hierarchy.