TransferGoal()?



  • On 23/08/2013 at 08:34, xxxxxxxx wrote:

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

    ---------
    Hi,
    I don't think I understand what TransferGoal() is supposed to be used for. Because when I use the TransferGoal() function. Nothing happens.
    To be more accurate. Something does happen. But only in memory.
    Nothing in the scene changes. And my link fields don't changed.

    Code example trying to transfer the BaseLink object from one camera to another using TransferGoal() :

        BaseObject *cam1 = doc->SearchObject("cam1");   //A camera with a cube object in it's Focus Object link field  
      if(!cam1) return FALSE;  
      
      BaseContainer *bc = cam1->GetDataInstance();  
      BaseObject *linkedOp = (BaseObject* )bc->GetLink(CAMERAOBJECT_TARGETOBJECT, doc, Obase); //Grab the cube object in the link field  
        
      BaseObject *cam2 = doc->SearchObject("cam2");   //A camera with nothing in it's Focus Object link field  
      if(!cam2) return FALSE;  
      
      cam1->TransferGoal(cam2, FALSE);                //Transfer the Focus Object linked object from cam1 to cam2....Nothing happens?  
      cam2->Message(MSG_UPDATE);  
      
      cam1->Remove();                                 //Delete camera1  
      
      EventAdd();
    

    From the docs:
    "Transfer goals from this object to dst. This changes all BaseLink links that point to this object to point to dst instead"

    I'm reading that sentence as: "Use this function to move your linked objects from one object's link field to another object's link field." But it's not working as expected for me.
    Could it be that the docs are referring to classes as the "objects". Rather than actual objects in the scene?

    I couldn't find any examples of this code in use anywhere.

    -ScottA



  • On 23/08/2013 at 08:49, xxxxxxxx wrote:

    Howdy,

    Well, you're using it backwards.

    This is how you'd use it:

    BaseObject *cam1 = doc->SearchObject("cam1");   //A camera with a cube object in it's Focus Object link field
    if(!cam1) return FALSE;
      
    BaseContainer *bc = cam1->GetDataInstance();
    BaseObject *linkedOp1 = (BaseObject* )bc->GetLink(CAMERAOBJECT_TARGETOBJECT, doc, Obase); //Grab the cube object in the link field
      
    BaseObject *linkedOp2 = doc->SearchObject("Cube2");   //An object not linked to the camera
    if(!linkedOp2) return FALSE;
      
    linkedOp1->TransferGoal(linkedOp2, FALSE); // Transfer the objects in the camera's link
    cam1->Message(MSG_UPDATE);
      
    EventAdd();
    

    Adios,
    Cactus Dan



  • On 23/08/2013 at 09:22, xxxxxxxx wrote:

    Thanks Dan.
    But now the docs make even less sense to me.

    That is "swapping" objects in one object's BaseLink.
    Not transferring them from one BaseLink to another BaseLink.

    I'm starting to think more and more that by "object". They meant classes. Not BaseObjects.

    -ScottA



  • On 23/08/2013 at 10:17, xxxxxxxx wrote:

    Howdy,

    Well, remember that in C++ a class is also referred to as an "object", as in "object oriented programming". So, when you think of it along those lines, the SDK documentation for the TransferGoals() function makes more sense. 😉

    Adios,
    Cactus Dan



  • On 23/08/2013 at 11:04, xxxxxxxx wrote:

    Arggh!😠
    It's just not making any sense.

    I found a different way to transfer a BaseLink to another object's BaseLink using CopyTo:

        BaseObject *cam1 = doc->SearchObject("cam1");   //A camera with a cube object in it's Focus Object link field  
      if(!cam1) return FALSE;  
      BaseContainer *bcCam1 = cam1->GetDataInstance();  
      BaseObject *linkedCam1 = (BaseObject* )bcCam1->GetLink(CAMERAOBJECT_TARGETOBJECT, doc, Obase); //Grab the cube object in the link field  
      BaseLink *blCam1 = bcCam1->GetBaseLink(CAMERAOBJECT_TARGETOBJECT);  
      
        
      BaseObject *cam2 = doc->SearchObject("cam2");   //A camera with nothing in it's Focus Object link field  
      if(!cam2) return FALSE;  
      BaseContainer *bcCam2 = cam2->GetDataInstance();  
      BaseObject *linkedCam2 = (BaseObject* )bcCam2->GetLink(CAMERAOBJECT_TARGETOBJECT, doc, Obase);  
      BaseLink *blCam2 = bcCam2->GetBaseLink(CAMERAOBJECT_TARGETOBJECT);  
        
      blCam1->CopyTo(blCam2, COPYFLAGS_0, NULL);   
      cam2->Message(MSG_UPDATE);  
      
      cam1->Remove();                               //Delete camera1  
      
      EventAdd();
    

    But I really would like to know how to use the TransferGoal() function.
    Nothing I'm trying is working.

    -ScottA



  • On 23/08/2013 at 11:47, xxxxxxxx wrote:

    Howdy,

    Well, you may still be thinking about the TransferGoal() function backwards. It's not for transferring an object from one link field to another. It's for swapping objects in the same link field.

    From the looks of your code, it might be easier to do this:

    //A camera with a cube object in it's Focus Object link field
    BaseObject *cam1 = doc->SearchObject("cam1"); if(!cam1) return FALSE;
    BaseContainer *bcCam1 = cam1->GetDataInstance(); if(!bcCam1) return FALSE;
      
    //A camera with nothing in it's Focus Object link field
    BaseObject *cam2 = doc->SearchObject("cam2"); if(!cam2) return FALSE;
    BaseContainer *bcCam2 = cam2->GetDataInstance(); if(!bcCam2) return FALSE;
      
    //Transfer the cube from cam1's Focus Object link to cam2's Focus Object link
    bcCam2->SetLink(CAMERAOBJECT_TARGETOBJECT, bcCam1->GetLink(CAMERAOBJECT_TARGETOBJECT, doc));
    cam2->Message(MSG_UPDATE);
      
    cam1->Remove();	//Delete camera1
      
    EventAdd();
    

    Adios,
    Cactus Dan



  • On 23/08/2013 at 12:28, xxxxxxxx wrote:

    But that's not what the docs say it does Dan.
    It does not say that it is for swapping objects into link fields.

    It says this:
    Transfer goals from this object to dst. This changes all BaseLink links that point to this object to point to dst instead.

    Follow my thinking here:
    -An object (BaseObject) is not a goal.
    -When you put an object into another object's link field. That it not "transferring".... That's linking.
    -Adding or replacing an object in a link field is not transferring a goal from one object to another
    -It says it changes "all BaseLink links that point to this object"
     Simply adding an object to another object's link field does not do this that I can see

    So I can't see how any of that translates into meaning swapping objects into link fields.
    You may be correct...But that's not what the docs are saying.
    To me it looks like it means that it's supposed to transfer BaseLinks (not BaseObjects) from one object to another object (whatever an "object" means is in question). And then update any pointers so that if the original object was deleted. C4D won't crash.

    The fact that we can also use it to add an object into the link field of another object seems like a side effect (an exploitation) to me. And not really main way to use it.
    But What I'm looking for is how to use it as it's written in the docs.
    How to use it to transfer BaseLinks and update pointers.

    If indeed all it does is put, or swap, objects into link fields like you say Dan.
    Then I apologize for being thick headed. But that's not what the docs say.

    -ScottA



  • On 23/08/2013 at 13:06, xxxxxxxx wrote:

    Howdy,

    Well, this is what I was talking about in that cgtalk thread when I said:

    ...I've noticed that the more I learn about C++ from other resources, the fewer questions I need to ask at plugin cafe, which is certainly less frustrating....

    In this case "object" is not referring to a BaseObject. It is referring to any C++ class object that inherits from a BaseList2D class. That's why the TransferGoal() function receives a BaseList2D as the parameter passed to it:
    Bool TransferGoal( BaseList2D * dst);

    ... and also why that function resides within the BaseList2D class object.

    If you look at the BaseLink class in the SDK documentation it says:

    ...A dynamic link to a BaseList2D object...

    The way I read and interpreted the first line in the documentation for the TranferGoal() function was:

    Transfer pointers that point to this BaseList2D to point to dst.

    ... which is exactly what the TransferGoal() function does. I've used TransferGoal() many times in my plugins, and it works exactly as described. Wink

    Adios,
    Cactus Dan



  • On 23/08/2013 at 13:57, xxxxxxxx wrote:

    Ok. I trust you.

    In my mind.
    Transfer goals from this object to dst   !=   Adds a BaseObject to an object's  BaseLink.
    Not even remotely.

    If I wanted to instruct someone that a function adds a BaseObject  to a BaseLink. That's exactly what I would write.
    I would never in a million years write: Transfer goals from this object to dst
    As the mayor said in Blazing Saddles about Gabby's speech. That's authentic western gibberish. 😂

    Thanks for the help,
    -ScottA



  • On 23/08/2013 at 14:54, xxxxxxxx wrote:

    Howdy,

    Yeah, I've found that every occupation has its own "lingo" and you have to learn the lingo before you can understand what folks are talking about. 😉

    Adios,
    Cactus Dan


Log in to reply