By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,703 Members | 1,230 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,703 IT Pros & Developers. It's quick & easy.

How to execute a string?

P: 1
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.

Expand|Select|Wrap|Line Numbers
  1. import c4d
  2. import os
  3. from c4d  import documents,storage
  4. fps = doc.GetFps()
  5. scenename = doc.GetDocumentName()  
  6. pathname = doc.GetDocumentPath()  
  7. rd = doc.GetActiveRenderData()
  8. sizeX = int(rd[c4d.RDATA_XRES_VIRTUAL])  
  9. sizeY = int(rd[c4d.RDATA_YRES_VIRTUAL])    
  10. sf = (rd[c4d.RDATA_FRAMEFROM]).GetFrame(fps)
  11. ef = (rd[c4d.RDATA_FRAMETO]).GetFrame(fps)
  12. sm ='"C:\\Program Files (x86)\\Smedge\\submit.exe"'  
  13.  
  14. #Fix Os Path  
  15. fn = os.path.join(pathname,scenename)
  16.  
  17. sj = str(sm) + "\n"
  18. sj += "Type = 986184cd-04c1-451f-af66-f2947e405434\n"
  19. sj += "Scene = " + str(fn) + "\n" 
  20. sj += "Range = " + str(sf) + " - " + str(ef) + "\n"
  21. sj += "Name = " + str(scenename) + "\n"
  22. sj += "PacketSize = 10\n"
  23. sj += "Pool = 68c19473-625f-4e7b-9fd3-a3ee79d331e1\n"
  24. sj += "CPUs = 4\n"
  25.  
  26. #write to Disk same path  
  27. file = open(doc.GetDocumentPath()+'/'+scenename+'.sj','w')  
  28. file.write(sj)  
  29. file.close()  
  30. # Execute for send to render Farm  
  31. exp = os.path.join(pathname,scenename+'.sj')
  32.  
  33. ex = storage.GeExecuteFile(exp)
  34.  
-bsides
Feb 21 '12 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 626
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.
Expand|Select|Wrap|Line Numbers
  1. import subprocess
  2. #Fix Os Path  
  3. fn = os.path.join(pathname,scenename)
  4.  
  5. sj=['"C:\\Program Files (x86)\\Smedge\\submit.exe"',
  6.     str(sm),
  7.     "Type = 986184cd-04c1-451f-af66-f2947e405434",
  8.     "Scene = "+str(fn),
  9.     "Range = " + str(sf) + " - " + str(ef),
  10.     "Name = " + str(scenename),
  11.     "PacketSize = 10",
  12.     "Pool = 68c19473-625f-4e7b-9fd3-a3ee79d331e1",
  13.     "CPUs = 4" ]
  14.  
  15. subprocess.call(" ".join(sj), shell=True) 
Link to Doug Hellmann's write-up on subprocess.
Feb 21 '12 #2

P: 1
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:

Expand|Select|Wrap|Line Numbers
  1. 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:

Expand|Select|Wrap|Line Numbers
  1. 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:

Expand|Select|Wrap|Line Numbers
  1. /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
Apr 24 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.