Solved How to print in the console ?

Hi,

With a simple script python, we can use 'print' to put a message in the console
But, with a python plugin this command don't work
I show my code here:

def Command(self, id, msg):
	if id == btnID:
		print 'Hello World!'				#silently fails (no message in the console)
		print('Hello World!')				#silently fails (no message in the console)
		gui.MessageDialog('Hello World!')	#opens a dialog box and displays the message

Thank you for your observations

Hi,

you can use the Python 2 keyword print in plugins just fine. Aside from the unusual eight space tab width of your code which could trip Python, you also are missing a return statement. Here is a minimal setup for a CommandData which does print something to the console via a dialog.

import c4d

class MyDialog(c4d.gui.GeDialog):
    """
    """
    def CreateLayout(self):
        """
        """
        self.AddButton(1000, c4d.BFH_LEFT, 200, 24, "button")
        return True

    def Command(self, cid, msg):
        """
        """
        if cid == 1000:
            print "Hello"
        return True

class MyCommandData(c4d.plugins.CommandData):
    """
    """
    def Execute(self, doc):
        """
        """
        dlg = MyDialog()
        dlg.Open(c4d.DLG_TYPE_MODAL, -1, -1, 200, 200)
        return True

if __name__ == "__main__":
    c4d.plugins.RegisterCommandPlugin(id=10000000, 
                                      str="test", 
                                      info=0, 
                                      icon=c4d.bitmaps.BaseBitmap(), 
                                      help="", 
                                      dat=MyCommandData())

Cheers
zipit

MAXON SDK Specialist
developers.maxon.net

I used the frame of your code to make plugins from scripts that I wrote, and now I can send my results to the console.
Thanks