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

    script and CLI [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 491 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/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"
      ------------------------------------------------------------------------

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

        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.

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

          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

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

            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.

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