Activate Camera -A very simple question for a noob

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 29/08/2011 at 21:03, xxxxxxxx wrote:

Originally posted by xxxxxxxx



Note: Using xrange() is more efficient and should always be used when you do not require a list.

Edit: Made layout more nice. :)

Your image files are not allowed aparently. What layout are you refering to?

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 29/08/2011 at 21:06, xxxxxxxx wrote:

You cannot see the images ? :cry:
Ehm, layout ? Do you mean websites ?
Actually, theese are the links:

Python Docs: http://docs.python.org/index.html
Xrange function: http://docs.python.org/library/functions.html?highlight=xrange#xrange
Range function: http://docs.python.org/tutorial/controlflow.html#the-range-function
for statement: http://docs.python.org/tutorial/controlflow.html#for-statements

Edit: Using the SaveDocument function works just fine and no dialog appears.

import c4d  
from c4d.documents import SaveDocument  
  
  
def main() :  
  SaveDocument(doc, 'C:\\foo.c4d', 1, c4d.FORMAT_C4DEXPORT)  
  
if __name__=='__main__':  
  main()

You just have to make sure that the file-path is absolute, not relative.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 29/08/2011 at 21:29, xxxxxxxx wrote:

Originally posted by xxxxxxxx

You cannot see the images ? :cry:
Ehm, layout ? Do you mean websites ?
Actually, theese are the links:

Python Docs: http://docs.python.org/index.html
Xrange function: http://docs.python.org/library/functions.html?highlight=xrange#xrange
Range function: http://docs.python.org/tutorial/controlflow.html#the-range-function
for statement: http://docs.python.org/tutorial/controlflow.html#for-statements

Edit: Using the SaveDocument function works just fine and no dialog appears.

import c4d  
from c4d.documents import SaveDocument  
 
 
def main() :  
  SaveDocument(doc, 'C:\\foo.c4d', 1, c4d.FORMAT_C4DEXPORT)  
 
if __name__=='__main__':  
  main()

You just have to make sure that the file-path is absolute, not relative.

Yeah mate I've got my head around that function now which is great.

However from the SDK there doesnt seem to be an option/flag to make it a 'SAVE PROJECT' function where the entire project folder is saved INCLUDING tex folder, GI files etc.

So I want to iterate the same function as when the user goes File/Save Project...

not sure if i made sense.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 29/08/2011 at 21:58, xxxxxxxx wrote:

Is there something more than textures and GI files ?
Copying the GI files and textures is no problem. It does also seem like cinema 4d does recognize when textures are suddenly relative and no more absolute.

Use this function to save as a project, It should work jsut fine.

import  c4d  
from    c4d.documents   import SaveDocument  
from    os.path         import abspath, dirname, split, join, exists, basename, isabs  
from    os              import makedirs, mkdir  
from    shutil          import copytree, copy  
  
def SaveProject(doc, path) :  
  pah         = abspath(path)  
  ndir_, name = split(path)  
  ndir_       = join(ndir_, name[:name.rfind('.')])  
  
  if not exists(ndir_) :  
      makedirs(ndir_)  
  
  new_illum   = join(ndir_, 'illum')  
  new_tex     = join(ndir_, 'tex')  
  
  dir_    = doc.GetDocumentPath()  
  if dir_:  
      illum   = join(dir_, 'illum')  
      if exists(illum) :  
          copytree(illum, new_illum)  
      tex     = join(dir_, 'tex')  
      if exists(tex) :  
          copytree(tex, new_tex)  
  
  for i, texture in doc.GetAllTextures() :  
      if not isabs(texture) : continue  
      copy(texture, join(new_tex, basename(texture)))  
  
  SaveDocument(doc, join(ndir_, name), 0, c4d.FORMAT_C4DEXPORT)  
  
  return True  
  
# example:  
SaveProject(doc, 'C:\\foo.c4d')

Cheers,

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 29/08/2011 at 22:44, xxxxxxxx wrote:

Absolute genius Nux, and that was quick too! You saved me ages! :beer:

Im sure a lot of readers will find this particularly useful too!

Thanks mate.

PS. does the \\ in the filename denote multiplatform? Would this work on a mac for instance? Thanks again.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 29/08/2011 at 23:32, xxxxxxxx wrote:

Here is something interesting. For some reason this doesnt bring in my one material for the 3Dcam.c4d scene. It is definately there in the file. I've tried flags but it doesnt make a difference...mmm

import c4d, os  
from c4d import documents  
  
def main() :  
  doc = documents.GetActiveDocument()  
  fn = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_DESKTOP) #Gets the desktop path  
  path = os.path.join(fn,'3Dcam.c4d')                #The actual .c4d file   
  merge = documents.MergeDocument(doc, path, 1 )  
  c4d.EventAdd()  
  
if __name__=='__main__':  
  main()  
  

EDIT: Wait, replacing the merge = documents.MergeDocument(doc, path, 1 ) to  merge = documents.MergeDocument(doc, path, 3 )seemed to work. :)

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 30/08/2011 at 06:26, xxxxxxxx wrote:

Originally posted by xxxxxxxx

PS. does the \\ in the filename denote multiplatform? Would this work on a mac for instance? Thanks again.

The backslash is a character indicating a special character in a string on almost any programmin language. Using \\ defines a simple \. Using \n defines a newline, a tab, etc..

Originally posted by xxxxxxxx

EDIT: Wait, replacing the merge = documents.MergeDocument(doc, path, 1 ) to  merge = documents.MergeDocument(doc, path, 3 )seemed to work. :)

You should use IDs instead of numbers, but i couldn't find that numer to be a 'SCENEFILETER_XX' ID. Sounds weird. May you check the function with the IDs to see which one does work for you ? See the documentation for the IDs under MergeDocument. Thanks. ;-)

Np :wink:
Cheers,

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 30/08/2011 at 07:50, xxxxxxxx wrote:

Read this thread about escape characters:https://plugincafe.maxon.net/topic/5838/5896_saving-files-without-the-file-browser

Mac's and PC's use different escapes.
That might be the reason why the guy who made render elements was having troubles.

-ScottA

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 30/08/2011 at 20:36, xxxxxxxx wrote:

Originally posted by xxxxxxxx

Read this thread about escape characters:https://plugincafe.maxon.net/topic/5838/5896_saving-files-without-the-file-browser

Mac's and PC's use different escapes.
That might be the reason why the guy who made render elements was having troubles.

-ScottA
[/QUOTE

ah i see. thanks dude.

PS. I am trying this code to simply change the viewport resolution, not working...mmm

 
 renderData = document.GetActiveRenderData()
 renderData[c4d.RDATA_XRES] = 1024
 renderData[c4d.RDATA_YRES] = 576  
 document.SetActiveRenderData(renderData)  
 

thanks

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 30/08/2011 at 20:55, xxxxxxxx wrote:

I recall reading another thread where someone was also having problems with it.
I can't remember if he was a mac user or not.
It's never given me any trouble on the PC platform:

import c4d  
  
def main() :  
  renderData = doc.GetActiveRenderData()  
  renderData[c4d.RDATA_XRES] = 200  
  renderData[c4d.RDATA_YRES] = 200  
  c4d.EventAdd()  
  
if __name__=='__main__':  
  main()

Works fine for me.

-ScottA

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 30/08/2011 at 23:02, xxxxxxxx wrote:

Yeah spot on Scott, cheers.

So if i want to change the render savefilename or multipass filename based upon a user data variable, is this a similar procedure? Does this apply to document scale as well. I want to know how i can change the document scale to cm before i import my file with the script.

Cheers. Its coming together.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 30/08/2011 at 23:31, xxxxxxxx wrote:

k, scratch most of that. Im mostly stuggling to find what class controls the document scale/fps etc.

EDIT: Looking though the Base.Document reveals other things like min time, preview time FPS etc but no document scale (cm/mm) etc...

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 31/08/2011 at 02:15, xxxxxxxx wrote:

Ok guys, so i am writing a script using your code which basically puts a multi-cam project to a renderfarm with one click. IT makes x number project folders with each c4d containing different active cameras (using Xpresso).

I am just getting into the loop part to change the selected camera BEFORE it calls the SaveProject() function which Nux was so kind to provide. The script at the moment creates the folders correctly, but it is not changing the user data which in turn should be changing the active camera. I am sure its a simple syntax error and the way im getting the user data. Help? The User data ID which controls the selected camera is #17.

Thanks. PS. once this is sorted id like to be able to get the filename and renderfarm path dynamically from a string/dir user data. This is easy i suspect once someone clues me in on how i have skrewed up the currect code...

Thanks guys.

  
  
import  c4d  
from    c4d.documents   import LoadDocument, SaveDocument, GetActiveDocument, InsertBaseDocument  
from    os.path         import abspath, dirname, split, join, exists, basename, isabs  
from    os              import makedirs, mkdir  
from    shutil          import copytree, copy  
  
def SaveProject(doc, path) :  
  pah         = abspath(path)  
  ndir_, name = split(path)  
  ndir_       = join(ndir_, name[:name.rfind('.')])  
  
  if not exists(ndir_) :  
      makedirs(ndir_)  
  
  new_illum   = join(ndir_, 'illum')  
  new_tex     = join(ndir_, 'tex')  
  
  dir_    = doc.GetDocumentPath()  
  if dir_:  
      illum   = join(dir_, 'illum')  
      if exists(illum) :  
          copytree(illum, new_illum)  
      tex     = join(dir_, 'tex')  
      if exists(tex) :  
          copytree(tex, new_tex)  
  
  for i, texture in doc.GetAllTextures() :  
      if not isabs(texture) : continue  
      copy(texture, join(new_tex, basename(texture)))  
  
  SaveDocument(doc, join(ndir_, name), 0, c4d.FORMAT_C4DEXPORT)  
  
  return True  
  
# example:  
#SaveProject(doc, 'C:\\foo.c4d')  
  
def SaveLoop() :  
  doc          = GetActiveDocument()  
  selectedcam  = op[c4d.ID_USERDATA, 17] # id: the id of the userdata entry  
    
  
  for i in xrange(8) :  
      # ... Change whatever you want  
      selectedcam = i  
      c4d.EventAdd()  
      SaveProject(doc, r'D:\Scene_cam0' + str(i) + '.c4d')  
  
SaveLoop()  
  

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 31/08/2011 at 03:25, xxxxxxxx wrote:

You missunderstood how getting and setting of data and variable works.

selectedcam  = op[c4d.ID_USERDATA, 17]

This doesn't assign the actual userdata entry to 'selectedcam', it does assign it's value.

for i in xrange(8) :  
  op[c4d.ID_USERDATA, 17] = i

is the right code.

Again, I recommend you to read the tutorial in the documentation. It's a fundamental base for the knowledge you need for programming.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 31/08/2011 at 04:11, xxxxxxxx wrote:

Ok . Thanks anyway for all your help along the way.