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

    Command line parameter problem

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 355 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 19/08/2015 at 06:18, xxxxxxxx wrote:

      Hi,

      We are trying to develop a (Tag) plugin to switch camera's from the command line. We thought we had it working since it works when we open a c4d file in the GUI and it switches to the right camera, but when we render on the render farm (command line / nogui) it doesn't work. It gives us:

      File "'CommandLine.pyp'", line 31, in Execute
      AttributeError: 'module' object has no attribute 'argv'

      In the log

      This is the code:

      import c4d
      import os
      import sys
      import getopt

      print 'Number of arguments:', len(sys.argv), 'arguments.'
                print 'Argument List:', str(sys.argv)
                try:
                    opts, args = getopt.getopt(sys.argv,"c:s:",["camera=","setting="])
                except getopt.GetoptError as err:
                    print "Error: Unknown command line options!"
                    print "We only support -c|--camera= -s|--setting="
                    return False
                   
                camera = ''
                setting = ''
                for opt, arg in opts:
                    if opt in ("-c", "--camera") :
                        camera = arg
                        print "camera = ", camera
                    elif opt in ("-s", "--setting") :
                        setting = arg
                        print "setting = ", setting
                commandRead = 1
           
                adraw = doc.GetActiveBaseDraw()
                roots = doc.GetObjects()
               
                cameraFound = 0
                for obj in roots:
                    if obj.GetName() == camera:
                        adraw.SetSceneCamera(obj)
                        cameraFound = 1
                c4d.EventAdd()
                   
                if cameraFound == 1:
                    camname = adraw.GetSceneCamera(doc).GetName()
                    print "Camera :", camname, "selected"
                else:
                    print "Camera not Found!"

      Is getopt not availble during load? Of are we missing something here? I hope someone can help. We need this for a customer job.

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

        On 20/08/2015 at 02:54, xxxxxxxx wrote:

        Hi,

        To get the Cinema 4D command line arguments implement PluginMessage() and filter the C4DPL_COMMANDLINEARGS message. In this message sys.argv holds the command line arguments.
        You can then store them using a global variable to be used afterwards in your Tag's Execute().

        See Command Line Arguments in the Python documentation for a code snippet and more information.

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

          On 20/08/2015 at 14:09, xxxxxxxx wrote:

          Thank you very much 🙂 I'm going to try that.

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