Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    Activate Camera -A very simple question for a noob

    PYTHON Development
    0
    32
    17.8k
    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
      Helper
      last edited by

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

      On 29/08/2011 at 02:01, xxxxxxxx wrote:

      1. How about doing it the other wey round ? Instead of loading the Scene to the Preset, load the Preset to the scene. (That was actually my intention with the naming of the variables).

      2. op[c4d.ID_USERDATA, id] # id: the id of the userdata entry

      Cheers,

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

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

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

        Here's how to Merge a .c4d file:

        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,'MyFile.c4d')                #The actual .c4d file   
          merge = documents.MergeDocument(doc, path, 1)  
          c4d.EventAdd()  
          
        if __name__=='__main__':  
          main()
        

        Look up the other paths (C4D_PATH_DESKTOP, etc...)  you can use in the docs.

        -ScottA

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

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

          On 29/08/2011 at 17:26, xxxxxxxx wrote:

          Originally posted by xxxxxxxx

          Here's how to Merge a .c4d file:

          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,'MyFile.c4d')                #The actual .c4d file   
            merge = documents.MergeDocument(doc, path, 1)  
            c4d.EventAdd()  
           
          if __name__=='__main__':  
            main()
          

          Look up the other paths (C4D_PATH_DESKTOP, etc...)  you can use in the docs.

          -ScottA

          Thanks Scott, will try that asap. Ill let you know how i go.

          One thing I am still struggling with is how to setup that for loop with the user data. Like where do i need to specify the ID. and where do i put 'i' for an integer list type user data setup.

          Basically at the moment the user data integer list is set up so ...

          0=perspec using nux's little python script tag. (Thanks mate!)
          1=cam 1
          2=cam 2
          3=cam 3 etc...

          can you specify a for loop where i is between a range say 1-5 for example?

          I know Python integration is fairly new to c4d, but I am amazing how little true code examples there are on the net. Who can understand reading an SDK. Half of it isnt even in context. Just raw comands. And it's so brutal when it comes to debugging that somelike me has no chance to find what is wrong with the code.

          One thing i can say is how surprised I am of the support you guys have given me already. I know you think im lazy for asking for code, but I guess i learn faster with examples. And reverse engineering code rather than inventing it.

          Thanks all. 😄

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

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

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



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

            Edit: Made layout more nice. 🙂

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

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

              On 29/08/2011 at 20:50, xxxxxxxx wrote:

              Originally posted by xxxxxxxx

              Here's how to Merge a .c4d file:

              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,'MyFile.c4d')                #The actual .c4d file   
                merge = documents.MergeDocument(doc, path, 1)  
                c4d.EventAdd()  
               
              if __name__=='__main__':  
                main()
              

              Look up the other paths (C4D_PATH_DESKTOP, etc...)  you can use in the docs.

              -ScottA

              That worked and makes sense thank you.

              NUX; i'm going to attempt this for loop thing now from the documentation you posted. Will let you know when i fail...😂.

              Has anyone ever got Python to save the entire project including scene file and tex folder? 'Render Elements' does it, so i asked the creator how he did it and he said that there was no easy way. He had to gather all the information in the scene and collect files manually with his code. He basically rewrote the save project command in c4d. It was his understanding that saving a project could not be scriptable because it promts the user every time for a save path, meaning its useless for long loops etc. I would like my script to 'for loop' the scene x amount of times changing a user data entry each time, then save the entire project to it's own folder with it's name also being driven by a user data string variable.

              Saving a project through Python seems to be the next hurdle for me now.

              Thanks!

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

                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?

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

                  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 ? 😢
                  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.

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

                    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 ? 😢
                    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.

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

                      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,

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

                        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! 🍺

                        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.

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

                          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. 🙂

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

                            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 😉
                            Cheers,

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

                              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://developers.maxon.net/forum/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

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

                                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://developers.maxon.net/forum/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

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

                                  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

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

                                    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.

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

                                      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...

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

                                        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()  
                                          
                                        
                                        1 Reply Last reply Reply Quote 0
                                        • H
                                          Helper
                                          last edited by

                                          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.

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

                                            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.

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