script and CLI [SOLVED]

On 30/01/2017 at 08:13, xxxxxxxx wrote:

Hi there,

i am very new to this topic and i am testing a script that should give me an output in the CLI.
I am just running the CommandLine:
"C:\Program Files\MAXON\Cinema 4D R18\Commandline.exe" %userprofile%\Desktop est.c4d

and it ends up printing out:
Print Test successful! #2

Print Test successful! #3

I expect that it should also show me: "Print Test successful! #1" but it doesnt...

what am i doing wrong?

Script:
------------------------------------------------------------------------
import c4d
from c4d import plugins

Be sure to use a unique ID obtained from www.plugincafe.com

PLUGIN_ID = 5678901

Command Plugin

class PrintTestData(c4d.plugins.CommandData) :

def Execute(self, doc) :
      print "Print Test successful! #1"

return True

if __name__ == "__main__":
  plugins.RegisterCommandPlugin(id=PLUGIN_ID, str="Py-PrintTest",
                                help="Py - Print Test", info=0,
                                dat=PrintTestData(), icon=None)

print "Print Test successful! #2"
 
print "Print Test successful! #3"
------------------------------------------------------------------------

On 30/01/2017 at 15:06, xxxxxxxx wrote:

Where do you trigger this plugin?

It's a command plugin so the Execute() method is called when you select it from the menu, or click the icon, or perform CallCommand() in a script... if you just run some .c4d file from the command line, nothing like this happens, so the Execute() method is never called.

I admittedly don't know what your test.c4d is doing, but if there is no explicit call, the plugin code will be called once for registering, printing #2, and then end at #3, and the actual class just sits there waiting for you to click, never getting to #1.

On 31/01/2017 at 06:19, xxxxxxxx wrote:

Hi Square, thanks for writing us.

With reference to your question please note that script can be run only upon user interaction via the Script Manager whilst python plugins can be called from commandline. In order to do this, just save your plugin as a .pyp and locate it under the /plugins folder in your Cinema installation. Your plugin should also implement the PluginMessage() method where you're actually responsible for triggering your CommandData plugin call.

import os  
import math  
import sys  
import c4d
from c4d import plugins
  
# Generate a new plugin-id on PluginCafe and use it here
PLUGIN_ID = 01234567
  
#define your CommandData plugin  
class PrintTestData(c4d.plugins.CommandData) :  
  def Execute(self, doc) :  
      print "PrintTestData [Execute]"  
      return True
  
# implement the PluginMessage to parse the arguments defined on the command line  
def PluginMessage(id, data) :  
  if id==c4d.C4DPL_COMMANDLINEARGS:  
      if 'PrintTestData' in sys.argv:  
          print "Calling PrintTestData"  
          c4d.CallCommand(PLUGIN_ID)  
          print "Returning from PrintTestData"  
          return True
    return False
  
# register your plugin 
if __name__ == "__main__":  
  plugins.RegisterCommandPlugin(id=PLUGIN_ID,   
                                  str="Py-PrintTest",  
                                  help="Py - Print Test",   
                                  info=0,  
                                  dat=PrintTestData(),  
                                  icon=None)  
  print "Plugin PrintTestData registered"

In the command line, once reached the Cinema binary folder,  simply execute

\> Commandline PrintTestData

Cheers, R

On 31/01/2017 at 08:41, xxxxxxxx wrote:

Thank you!

That was exactly what i was looking for... works perfect!
Now i can dive deeper to achieve my goal.