Reading base link



  • On 08/12/2014 at 03:41, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R14 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Hi Folks,
     
    what's the correct way to get/set a class level BaseObject link/reference? I've been trying with saving the scene and using a base link in a GeData's BaseList2D variable like the following:

    MyObject::Write(..)
    {
        GeData data;
        data.SetBaseList2D((BaseList2D* )MyClassLevelObject);  
        hf->WriteGeData(data);
    }
    

    And in the Read() I'm doing variations like this:

    MyObject::Read(GeListNode *node,HyperFile *hf,LONG Level)
    {
        BaseDocument *doc = node->GetDocument();
        GeData data;  
        hf->ReadGeData(&data);
        GePrint("data's type = " + LongToString(data.GetType()));  // prints type 133 = alias link  
        MyClassLevelObject = (BaseObject* )data.GetLink(doc,NULL);  // returns NULL
    }
    

    What's my undoing here?
     
    WP.



  • On 08/12/2014 at 05:27, xxxxxxxx wrote:

    It is possible on Read() that the linked object does not exist in the document yet due to ordering of creation in C4D so that method is untrustworthy.   I would also caution against using pointers (memory addresses) for storing data structures in file.

    You could add a LINK description to your object and the link is automatically saved and loaded with the plugin object (document file) instead.  C4D maintains the proper linked object reference.  If you want, the description element can be hidden from the A.M. interface (i.e.: HIDDEN keyword) so that the user does not see it.

    If the element must be dynamic, then GetDDescription() must be used and it gets trickier since now you must maintain a method to recreate the Link to the same object in the document (or in memory) each time.



  • On 08/12/2014 at 05:58, xxxxxxxx wrote:

    Hello,

    as mentioned above the easiest way should be to save the BaseLink in the object's BaseContainer. To handle such links don't store a pointer to an object. Use the BaseLink class. This class offers the necessary Read(), Write() and CopyTo() methods.

    Best wishes,
    Sebastian



  • On 10/12/2014 at 23:21, xxxxxxxx wrote:

    Hi Robert/Sebastian!

    Originally posted by xxxxxxxx

    If the element must be dynamic, then GetDDescription() must be used and it gets trickier since now you must maintain a method to recreate the Link to the same object in the document (or in memory) each time.

    I'm using a customgui plugin to do just this, and holding the references in a struct. I'm only using the link fields to grab the object. So once the object is grabbed, the link gui element is no longer needed, and is set to NULL and hidden (until the user needs the link again). This all appears to be working as expected - for instance I can do work on the referenced objects seemingly without any troubles.

    Originally posted by xxxxxxxx

    To handle such links don't store a pointer to an object. Use the BaseLink class. This class offers the necessary Read(), Write() and CopyTo() methods

    I've tried using BaseList2D/BaseLink/C4DAtom and saving a baselink into the obj->GetDataInstance() basecontainer, but all are returning null objects when I reload/open the scene file. So I don't know if that means there's something in my code causing the problem, but reading past topics, others appear to of had the same problem and have commented that the possible cause is that the objects you're trying to link to don't exist in the scene document yet (which Robert eluded too above). I feel a bit confused with this one. There doesn't seem to be a clear working guide to go with.
     
    WP.



  • On 11/12/2014 at 02:25, xxxxxxxx wrote:

    Hello,

    Originally posted by xxxxxxxx

    I'm using a customgui plugin to do just this, and holding the references in a struct. I'm only using the link fields to grab the object. So once the object is grabbed, the link gui element is no longer needed, and is set to NULL and hidden (until the user needs the link again).

    this sound a little weird to me. When you are hiding the linkbox anyway I would not set it to null. Instead I would keep using the linkbox to get the linked object when I need to work with it. Without knowing more of your code I can't tell much more.

    Best wishes,
    Sebastian



  • On 11/12/2014 at 20:38, xxxxxxxx wrote:

    The problem I've found with that though Sebastian is that I can't set link fields with objects that my object plugin owns. My plugin holds links to a mix of both scene document objects and internal objects. On top of this, each indexed container can have any number of versions of the object in question. For example, 5 links whom each hold 5 versions requires 25 references, but there can only ever be 5 objects 'in use' at any one time.
     
    So to keep consistency across the board, I simply don't use the link field, other than to catch the drag and dropped object. The link field is hidden and an edit text field is shown instead, which I set with the name of the object that that particular index is using. That side of the plugin seems to work well.
     
    It would make more sense if I showed you the object/plugin itself, but I can't do that until the reading and writing of the object references work - otherwise I can't pass an example scene file where you can see it working! :)
     
    WP.



  • On 12/12/2014 at 01:36, xxxxxxxx wrote:

    Hello,

    as I said, I wouldn't store BaseObjects directly but use BaseLink object's. So when you get the object from a LinkBox you can put it into a BaseLink and use that BaseLink to access this object later. For objects that are not part of a document you may need to use ForceGetLink().

    Maybe you should handle a own BaseDocument that stores your "owend" objects. But these are just some ideas based on what you tell. Without any code it's hard so say anything.

    Best wishes,
    Sebastian



  • On 19/12/2014 at 09:38, xxxxxxxx wrote:

    Hello WickedP,

    was your question answered?

    best wishes,
    Sebastian



  • On 20/12/2014 at 17:32, xxxxxxxx wrote:

    Hi Sebastian,

    I'm making a few changes to some of the guts of the plugin in the hope to finish off the working side of it. Might then be able to post the plugin itself (or a link to a download/video) so you can see what the plugin is and the idea of what the plugin does (and what it needs!). Bare with me for a little more, will see if I can get this done for sometime this week.

    WP.



  • On 15/01/2015 at 01:25, xxxxxxxx wrote:

    Hi Sebastian,

    my apologies for not getting back to this one sooner. I've had a life curve ball thrown at me and I'm needing to spend some time sorting out other things which have taken priority.

    If you're wanting to close/archive this topic, I can start a new one when I'm able to step back into it again.

    Kind regards,

    WP.



  • On 16/01/2015 at 09:51, xxxxxxxx wrote:

    Hello,

    I hope everything will be alright. We will close this thread and we are happy to help you when you work on this again.

    best wishes,
    Sebastian


Log in to reply