On 09/02/2016 at 09:44, xxxxxxxx wrote:
Cinema 4D Version: R15-R17
Platform: Windows ;
Language(s) : C++ ;
Probably this is an stupid question but I'm totally newbie to C4D itself (not only SDK) but as far as I could imagine this should work...
Lets imagine I have an ObjectData called OD_A and other called OD_B I can create both properly from plugins menu and all is ok, but at certain point I need to create several OD_B instances inside my OD_A
And I did something like:
BaseObject* obj = BaseObject::Alloc(ID_OD_B);
OD_B* node = (OD_B* )obj->GetNodeData();
but nothing seems to happen, obviusly the code is already running since I can insert a messagebox in the if(obj) part and it was shown.
Thank you to everyone in advance.
On 09/02/2016 at 10:14, xxxxxxxx wrote:
Have you inserted the 'virtualparent' into the document (GetActiveDocument())? Typically it goes like this:
// Allocate and insert object into document
BaseObject* objA = BaseObject::Alloc(type_A);
// Insert object into current document
GetActiveDocument()->InsertObject(objA, NULL, NULL);
// Notify to update everything
BaseObject* objB = BaseObject::Alloc(type_b);
// Insert object as child of first objA
On 09/02/2016 at 10:21, xxxxxxxx wrote:
THANK YOU SO MUCH!!!
I've spent lots of ours without any luck trying to figure this!!!
On 10/02/2016 at 09:10, xxxxxxxx wrote:
sorry for being late to the party.
Actually you don't tell us, where you want to execute your code.
But as a general rule, you shouldn't use GetActiveDocument() in NodeData derived plugins (so this applies for ObjectData as well). Instead you should rather retrieve the document from the node (e.g. obj->GetDocument()).
The thing is, these NodeData plugins get executed in situations, where there is no active document (e.g. when being rendered).
Next thing of course, always check for nullptrs. Never ever use GetActiveDocument()->..., because there could be a nullptr returned. Of course there may be situations, where you can be sure to have an active document. And if you are, the above code can still be fine. But you should think about it to make sure.
Same is true, when using GetDocument() on a node. There are situations, where a node is not inserted in a document (for example in CopyTo() situations, the destination node). So you need to check for nullptr there as well.
So please keep this in mind. As I said, I can't tell if it's wrong in your case, but you should rather check.
On 10/02/2016 at 10:02, xxxxxxxx wrote:
thank you for the tips!