fire a dev inside a class from a dialog class

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

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".

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 ;-)

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.