Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    AddConnection not working properly [SOLVED]

    SDK Help
    0
    3
    377
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      On 22/05/2015 at 03:40, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   R16 
      Platform:      Mac OSX  ; 
      Language(s) :     C++  ;

      ---------
      Hi,

      Inside my ObjectData plugin I'm setting up XPresso nodes when a button has been pressed.
      So far, everything works, except the connection adding.

      Here is my code:

        
      #include "c4d.h"  
      #include "c4d_symbols.h"  
      #include "omyplugin.h"  
      #include "main.h"  
      #include "c4d_basedocument.h"  
      #include "c4d_graphview.h"  
      #include "gvmath.h"  
        
      class MyPluginData : public ObjectData  
      {  
        INSTANCEOF(MyPluginData, ObjectData)  
        
      public:  
        virtual Bool Init(GeListNode* node);  
        virtual Bool Message(GeListNode* node, Int32 type, void* data);  
        
        static NodeData* Alloc(void) { return NewObjClear(MyPluginData); }  
      };  
        
      Bool MyPluginData::Message(GeListNode* node, Int32 type, void* data)  
      {  
        if (type == MSG_MENUPREPARE)  
        {  
            ((BaseObject* )node)->GetDataInstance()->SetInt32(PRIM_PLANE, PRIM_PLANE_XZ);  
        }  
        else if (type == MSG_DESCRIPTION_COMMAND)  
        {  
            DescriptionCommand* dc = (DescriptionCommand* )data;  
            if (dc->id[0].id == CREATE_CHARACTER)  
            {  
                BaseObject* op = (BaseObject* )node;  
                if (op)  
                {  
                    XPressoTag* myXPressoTag = static_cast<XPressoTag*>(op->MakeTag(Texpresso, NULL));  
                    if (!myXPressoTag)  
                        return false;  
                    GvNodeMaster* myNodeMaster = myXPressoTag->GetNodeMaster();  
                    if (myNodeMaster)  
                    {  
                        GvNode* mathNode = myNodeMaster->CreateNode(myNodeMaster->GetRoot(), ID_OPERATOR_MATH);  
                        if (!mathNode)  
                            return false;  
                        mathNode->SetParameter(GV_DYNAMIC_DATATYPE, ID_GV_DATA_TYPE_INTEGER, DESCFLAGS_SET_0);  
                        mathNode->SetParameter(GV_MATH_FUNCTION_ID, GV_MUL_NODE_FUNCTION, DESCFLAGS_SET_0);  
                        GvPort* mathFirstInPort = mathNode->GetPort(1000);  
                        GvPort* mathSecondInPort = mathNode->GetPort(1001);  
                        GvPort* mathOutPort = mathNode->GetOutPort(0);  
                        const DescID id = DescID(DescLevel(GV_MATH_INPUT, DTYPE_SUBCONTAINER, 0), DescLevel(1001, DTYPE_LONG, 0));  
                        mathNode->SetParameter(id, Int32(-1), DESCFLAGS_SET_0);  
                        GvNode* resultNode = myNodeMaster->CreateNode(myNodeMaster->GetRoot(), ID_OPERATOR_RESULT, nullptr, 150, 0);  
                        if (!resultNode)  
                            return false;  
                        GvPort* resultInPort = resultNode->GetPort(1000);  
        
                        if (myNodeMaster->IsConnectionValid(mathNode, mathOutPort, resultNode, resultInPort, mathNode, mathOutPort, resultNode, resultInPort))  
                        {  
                            mathNode->AddConnection(mathNode, mathOutPort, resultNode, resultInPort);  
                        }  
                    }  
                    else  
                    {  
                        return false;  
                    }  
                }  
                else  
                {  
                    return false;  
                }  
            }  
        }  
        return true;  
      }  
        
      Bool MyPluginData::Init(GeListNode* node)  
      {  
        BaseObject* op = (BaseObject* )node;  
        BaseContainer* data = op->GetDataInstance();  
        if (!data)  
            return false;  
        return true;  
      }  
        
      #define ID_MYPLUGIN 1000008  
        
      Bool RegisterMyPlugin(void)  
      {  
        return RegisterObjectPlugin(ID_MYPLUGIN, GeLoadString(IDS_MYPLUGIN), OBJECT_GENERATOR, MyPluginData::Alloc, "omyplugin", nullptr, 0);  
      }  
      

      It seems to work only half. My math output port has a dot inside it's circle (see image), just as result has in its input port. The only thing that seems missing is the actual connection (line).
      I'm also sure that it isn't connected, because the result node still has the input value inside the attribute manager (see image).

      The image can be found here: http://i59.tinypic.com/t0gkur.png

      Does anybody know what could be the problem here?
      If you need more information, just ask me.
      Thanks in advance for your help and time!
      Greetings,
      Casimir Smets

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 26/05/2015 at 04:56, xxxxxxxx wrote:

        Hi Casimir,

        I'm sorry, this took a bit longer.
        Instead of

          mathNode->AddConnection(mathNode, mathOutPort, resultNode, resultInPort);
        

        call AddConnection on the node with the input (where the connection ends), like so:

          resultNode->AddConnection(mathNode, mathOutPort, resultNode, resultInPort);
        

        I will add a note to the SDK docs for this.

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 01/06/2015 at 01:24, xxxxxxxx wrote:

          Hi Andreas,

          Thanks you very much for your answer!
          You can mark this post as solved.

          Greetings,
          Casimir Smets

          1 Reply Last reply Reply Quote 0
          • First post
            Last post