How to execute a string?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bsides
    New Member
    • Feb 2012
    • 1

    How to execute a string?

    I'm trying to create a simple script to use in Cinema 4D that will push the render settings to an external render manager called Smedge. The script is in Python. I haven't really done any programing in python, so I'm sort of stuck right now. Right now my script kicks out a file with my collected data in it, but I'm not sure how to make it execute. I've tried exec and eval. I don't really need it to kick out a file, I just did that so I could see how the information was getting formated. This is the code I've come up with so far. Any help would be appreciated. I can format it as a command line too if that would be easier.

    Code:
    import c4d
    import os
    from c4d  import documents,storage
    fps = doc.GetFps()
    scenename = doc.GetDocumentName()  
    pathname = doc.GetDocumentPath()  
    rd = doc.GetActiveRenderData()
    sizeX = int(rd[c4d.RDATA_XRES_VIRTUAL])  
    sizeY = int(rd[c4d.RDATA_YRES_VIRTUAL])    
    sf = (rd[c4d.RDATA_FRAMEFROM]).GetFrame(fps)
    ef = (rd[c4d.RDATA_FRAMETO]).GetFrame(fps)
    sm ='"C:\\Program Files (x86)\\Smedge\\submit.exe"'  
      
    #Fix Os Path  
    fn = os.path.join(pathname,scenename)
       
    sj = str(sm) + "\n"
    sj += "Type = 986184cd-04c1-451f-af66-f2947e405434\n"
    sj += "Scene = " + str(fn) + "\n" 
    sj += "Range = " + str(sf) + " - " + str(ef) + "\n"
    sj += "Name = " + str(scenename) + "\n"
    sj += "PacketSize = 10\n"
    sj += "Pool = 68c19473-625f-4e7b-9fd3-a3ee79d331e1\n"
    sj += "CPUs = 4\n"
    
    #write to Disk same path  
    file = open(doc.GetDocumentPath()+'/'+scenename+'.sj','w')  
    file.write(sj)  
    file.close()  
    # Execute for send to render Farm  
    exp = os.path.join(pathname,scenename+'.sj')
    
    ex = storage.GeExecuteFile(exp)
    -bsides
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    You don't want the newlines, "/n" when you are entering command line arguments. This should be close, but generally there are no spaces except to separate arguments, so
    Type = 986184cd-04c1-451f-af66-f2947e405434
    maybe should be
    Type=986184cd-04c1-451f-af66-f2947e405434, etc.
    Code:
    import subprocess
    #Fix Os Path  
    fn = os.path.join(pathname,scenename)
     
    sj=['"C:\\Program Files (x86)\\Smedge\\submit.exe"',
        str(sm),
        "Type = 986184cd-04c1-451f-af66-f2947e405434",
        "Scene = "+str(fn),
        "Range = " + str(sf) + " - " + str(ef),
        "Name = " + str(scenename),
        "PacketSize = 10",
        "Pool = 68c19473-625f-4e7b-9fd3-a3ee79d331e1",
        "CPUs = 4" ]
    
    subprocess.call(" ".join(sj), shell=True)
    Link to Doug Hellmann's write-up on subprocess.

    Comment

    • uberware
      New Member
      • Apr 2012
      • 1

      #3
      Hi. Robin from Uberware here, creator of Smedge. I just saw this post and wanted to comment on the format of your command line. In order to submit a job using the command line format of the Submit tool that comes with Smedge, you need to adjust your command line syntax a bit. Here is an example of a correct command line that can submit to Smedge:

      Code:
      Submit.exe Script -Type Cinema 4D -Scene X:\Path\To\My\Scene.c4d -Range 1-100 -Name My Job Name -PacketSize 10 -CPUs 4
      Note that instead of using a NAME = VALUE type syntax, it uses a syntax like -NAME VALUE. You should adjust your script to use that format. Also, to submit automatically without accidentally starting any sort of interactive requests from Submit, you should add the "script" keyword before any parameters.

      If you want to save out the file as a .SJ file and then submit it that way, your code to save the file is correct (it should be a NAME = VALUE pair) but you need a section header for the job with an ID in it (though the ID doesn't matter, so you can just make one up or use all 0s). Then the command line syntax to submit from the file will be like this:

      Code:
      Submit.exe -FromFile X:\Path\To\The\SJFILE.sj
      Note in this case, you do not include the "script" keyword, but you must use the -FromFile flag and specify the full path to the .SJ file.

      Also, these should work identically on both Windows and Mac. On a Mac, the Submit tool is located in a folder hidden inside of the Smedge application bundle, and does not include the .EXE extension. For example, your command could look something like this:

      Code:
      /Applications/Smedge.app/Contents/MacOS/Submit Script -Type Cinema 4D -Scene /Path/To/My/Scene.mb -Range 1-100 -Name My Job Name -PacketSize 10 -CPUs 4
      Smedge can automatically translate the path to your scene file between Mac and Windows, so that you can submit a scene created on your Mac and render on both your Mac and Windows machines at the same time. Note, however, that Smedge does not modify any of the paths inside of the scene file itself, so your must make sure that your source textures are specified using a relative path name or using a format that can translate correctly, as needed.

      Please feel free to contact us if you have any questions about using Smedge and Cinema 4D. Thank you,

      -robin
      Last edited by uberware; Apr 24 '12, 01:21 AM. Reason: Mistakes in my command line

      Comment

      Working...