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