Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    Allowing plugins to talk to eachother?

    SDK Help
    0
    26
    17.4k
    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 15/01/2013 at 09:07, xxxxxxxx wrote:

      Wow.That's really great.
      Thanks a lot Niklas. 🍺

      Sorry it took up so much of your time.

      -ScottA

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

        On 25/01/2013 at 08:58, xxxxxxxx wrote:

        Has anyone ever used friend classes within these C4D plugins?
        In some cases it would be much less complicated if the two plugins simply had access to each others class members. Rather than using a third party interface to make them communicate.

        I've Googled about friend classes trying to learn how to write them.
        But when I try to use them inside of these plugins. I can't get it to work.
        I can set up the basic framework so it will compile without errors. But when I try to access the member variables from the other class. I get undefined type errors.

        Example:

          
        //Forward declare the tag so the Dialog can access it  
        class MyTag;  
          
        class MyDialog : public GeDialog  
        {  
          public:   
              virtual blah, blah, blah;  
              virtual blah, blah, blah;  
            
              LONG dialogMemberVariable;  //A class member that the tag can also access  
          
              friend MyTag;  
          
        };  
        ...  
          
        //How do I access use the tagMemberVariable without getting undefined class errors?  
          
          
        class MyTag : public TagData  
        {  
          public:  
              virtual blah, blah, blah;  
              virtual blah, blah, blah;  
            
              LONG tagMemberVariable; //A class member that the dialog can also access  
          
              friend MyDialog;   
        };  
          
          //How do I access use the dialogMemberVariable without getting undefined class errors?  
          
        ...
        

        -ScottA

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

          On 27/01/2013 at 11:59, xxxxxxxx wrote:

          Hi Scott,

          The friend keyword allows the specified class to access protected and private attributes and
          methods. Both of your classes have public members only, the friend keyword does not have any
          effect.

          Best,
          Nik

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

            On 27/01/2013 at 13:42, xxxxxxxx wrote:

            Hiya Nik,

            I learned a bit more about how to use friend yesterday.
            I've a good raw C++ example now that I'm using as a learning tool:

            //This is an example of using a custom method to access two different class's members  
            //By making the method a friend of both of the classes  
              
            #include <iostream>  
            #include <string>  
            using namespace std;  
              
            class Class2;     //Forward declare Class2 so Class1 knows what's inside of it   
              
            class Class1  
            {  
              public:  
                int a, b;  
                Class1() : a(1), b(2) { }    //Constructor sets the class variable values  
                friend void change(Class1 c1, Class2 c2);  
            };  
              
            class Class2  
            {  
              public:  
                int j;  
                Class2() : j(3) { }        //Constructor sets the class variable value  
                friend void change(Class1 c1, Class2 c2);   
            };  
              
            void change(Class1 &x1, Class2 &x2)  
            {  
              x1.a = 10;          //Changes the Class1 variable from 1 to 10  
              x2.j = 45;        //Changes the Class2 variable from 3 to 45  
              
                  //Compare the members from the two different classes  
              if(x1.a < x2.j) cout << "Class1 member a is less than Class2 member j" <<endl;  
            }  
              
            int main()  
            {  
              Class1 c1;  
              Class2 c2;  
              change(c1,c2);  
              
              cout<< "Class1 member a= "<< c1.a <<endl;  
              cout<< "Class2 member j= "<< c2.j <<endl;  
              
              system("pause");   //Keeps the console open until the Enter key is pressed  
              return 0;  
            }
            

            The problem I'm having with this in C4D plugins is that we don't use main() quite the same way as in raw C++.
            I think I need to place a prototype of the function that's the friend of the classes in the main.cpp file of C4D plugins. But I'm having a problem with the parameters part.

            I can make a void type prototyped method without any parameters work fine in the C4D main.cpp file.
            But when the method has params. in it ( In this cases the two classes). I'm having a hard time getting that to work in the main.cpp file.

            -ScottA

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

              On 27/01/2013 at 14:04, xxxxxxxx wrote:

              Hi Scott,

              I'm a little-bit confused. You never call the method check() of either class. The methods are defined,
              but not implemented, nor ever referenced. What should this example actually demonstrate?

              class A {
                  friend B;
                  private:
              
                      void DoPrivateStuff();
              
                  public:
              
                      void DoPublicStuff();
              };
              
              class B {
                  private:
              
                      void DoPrivateStuff();
              
                  public:
              
                      void DoPublicStuff();
              };
              

              While class A has access to B::DoPublicStuff() only, class B has access to A::DoPublicStuff()
              and A::DoPrivateStuff().

              -Nik

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

                On 27/01/2013 at 14:16, xxxxxxxx wrote:

                Oops. Sorry about that.
                "check" should be "changed".
                I changed it.

                The problem I'm having is calling the changed() type function when doing it in a C4D plugin.
                main() is written slightly differently in these C4D plugins.  And I'm having a problem with those differences.
                Specifically. I'm having a hard time prototyping functions that have params. in them in the C4D main.cpp file.

                -ScottA

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