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
    • Recent
    • Tags
    • Users
    • Login

    fire a dev inside a class from a dialog class

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 422 Views
    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 Offline
      Helper
      last edited by

      On 30/10/2015 at 17:12, xxxxxxxx wrote:

      Hi all,

      how can I start a def inside a class started from a def inside dialog class. I get a unbound python error.

      thanks in advance.

      some exmaple pseudocode

        
      class dialog() :   
          def maindialog() :   
              worker.dosomething(dialogid=5) #error raised herer   
        
      class worker() :   
          dosomething(dialogid) :   
              result = dialogid+10   
              return result
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 30/10/2015 at 17:30, xxxxxxxx wrote:

        You are calling dosomething() with the class name alone, instead of with an instance of the class.

        If that is really intended, you need to declare the method as @staticmethod.

          
        import c4d   
          
        class dialog() :   
            @staticmethod   
            def maindialog() :   
                print worker.dosomething(dialogid=5)   
          
        class worker() :   
            @staticmethod   
            def dosomething(dialogid) :   
                result = dialogid+10   
                return result   
               
        def main() :   
            dialog.maindialog()   
        

        Prints "15".

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

          On 31/10/2015 at 04:20, xxxxxxxx wrote:

          thanks. and how do i call it with an instance of that class ? for your info I am winging it here 😉

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

            On 31/10/2015 at 07:26, xxxxxxxx wrote:

            A method that is instance bound needs a parameter "self" so it can be called through
            instance.method(parameters)
            Then you can create a variable of the newly defined class, and call the methods on it:

              
            import c4d   
              
            class dialog() :   
                def maindialog(self) :   
                    x = worker()   
                    print x.dosomething(dialogid=5)   
              
            class worker() :   
                def dosomething(self, dialogid) :   
                    result = dialogid+10   
                    return result   
              
            def main() :   
                dlg = dialog()   
                dlg.maindialog()   
            

            Nevertheless: These are totally basic Python concepts. If you struggle with these already, you should perhaps take a Python tutorial and familiarize yourself with Python and OOP concepts. I don't know whether you have any programming knowledge in some other language, but here is a tutorial that may be of help:

            http://www.bogotobogo.com/python/python_introduction.php
            (There are tons of others on the web...)

            "Winging it" will probably not do you any good if you need to ask for every little bit of information; this would make for a very frustrating experience.

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