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

    Method `BaseTake.SetCamera(self, takeData, camera)` does not set the camera

    Cinema 4D SDK
    r21 python
    2
    6
    749
    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.
    • P
      paula.kokic
      last edited by

      Hello everyone,

      I am developing Python Plugins for C4D R21(did not update to Python3 yet) and I am having issues with generating takes. I am trying to set the render camera, but for some reason, after execution of the command, camera is not set (BaseTake.GetCamera(self, takeData) returns None). This method works completely fine in other parts of the plugin (that my ex-colleague wrote), with almost the same conditions.

      The method I am using to set the camera is: BaseTake.SetCamera(self, takeData, camera)
      Description here: https://developers.maxon.net/docs/py/2023_2/modules/c4d.modules/takesystem/BaseTake/index.html?highlight=setcamera#BaseTake.SetCamera

      I am sure that camera I want to set is a proper C4D camera object, it is not Null. My take object is also initialized and render settings loaded. Are there any specific limitations to this method, or something else that needs to be taken into consideration when using the method, that I just cannot see at the moment?

      Thank you very much in advance!

      Kind regards,
      Paula

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @paula.kokic
        last edited by ferdinand

        Hello @paula-kokic,

        thank you for reaching out to us. We have an example on Github for using BaseTake.SetCamera. What also might be an obstacle is to allow overrides for the take you are trying to modify. Please refer to user manual to learn more about overrides. A source for confusion could also be simply not making the created take the active one, i.e., have it reflected in the viewport, or flag it as being "checked". I did provide a modified variant of the GitHub example for these two cases below.

        But in the end, this is all very speculative. Specifically for the scenario where "[...] this method works completely fine in other parts of the plugin [...], with almost the same conditions [..]", it is impossible to give any good answers without having executable code. When you are not at liberty to share your code publicly, you can send it to our sdk-email address. Please refer to our Forum Guide under Confidential Data when there are NDAs involved.

        Cheers,
        Ferdinand

        The very slightly modified example:

        """ Example for handling cameras with takes.
        
        Based on the GitHub example, I just added two lines prefixed with the the
        [FH] comment at the end.
        
        Based upon:
            https://github.com/PluginCafe/cinema4d_py_sdk_extended/blob/
            13f9d2a95b3a2593f2f72ab49c542a922b32dcbb/scripts/04_3d_concepts/
            scene_elements/take_system/takesystem_cameras_r17.py
        
        As discussed in:
            https://developers.maxon.net/forum/topic/13398/
        """
        import c4d
        
        
        def main():
            # The TakeData from the active document, holding all take information.
            if takeData is None:
                raise RuntimeError("Failed to retrieve the take data.")
        
            # Gets the currently selected objects
            selectedObjects = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_0)
        
            # Iterates the selected Objects
            for element in selectedObjects:
        
                # Checks if the object is a Camera object
                if not element.CheckType(c4d.Ocamera):
                    continue
        
                # Adds a Take for this camera
                cameraTake = takeData.AddTake(
                    "Take for Camera " + element.GetName(), None, None)
                if cameraTake is None:
                    continue
        
                # Defines the active camera for this Take
                cameraTake.SetCamera(takeData, element)
                
                # [FH] Set the camera take as checked, i.e., being respected in a 
                # rendering.
                cameraTake.SetChecked(True)
                
            # [FH] Set the last camera take we did create as the active one.
            takeData.SetCurrentTake(cameraTake)
        
            # Pushes an update event to Cinema 4D
            c4d.EventAdd()
        
        
        if __name__ == '__main__':
            main()
        

        MAXON SDK Specialist
        developers.maxon.net

        P 1 Reply Last reply Reply Quote 0
        • P
          paula.kokic @ferdinand
          last edited by

          @ferdinand Thank you very much for your answer!

          I checked if all that you wrote is present in my code - and it is.

          Indeed, my take is generated, but constantly from the wrong camera - to be precise: from the main scene camera instead the one I want to render from.

          Even if I dynamically create a new camera with c4d.CameraObject() and put it into SetCamera() method, it will work.

          However, I realized today that somehow hierarchical position of the camera object makes a difference. When the render camera is attached to the root of the document it works. If it's under a Null object (e.g. 3rd level), it doesn't work. Do you have any explanation why would this be a game changer?

          At the moment, my workaround would be to make a clone of my camera and insert it at the root of the document, create a take, and then delete it after usage - this seems to work completely fine.

          Even though I have a workaround, I would be interested in knowing what is the connection between object hierarchy and using SetCamera() method for the Take.

          Thanks again!

          Kind regards,
          Paula

          1 Reply Last reply Reply Quote 0
          • ferdinandF
            ferdinand
            last edited by

            Hello @paula-kokic,

            as I said, it is impossible to give an answer without additional data: code, scenes, etc. We found a bug regarding cameras and Takes in the batch renderer not long ago, so, you could also encounter an undiscovered bug. The hierarchy constraint you mention sounds a bit like a bug to me. But a user error is more likely in the end, especially when you say it is working in one place of the code but not in another. One thing that could also be a problem, is that you might be doing what you are doing from a threaded context. Adding takes is of course a way to modify the scene graph. Which is forbidden in a threaded context. Read more about this topic here.

            But again, without code and a scene where this does happen for you, it is not possible to help you here reliably. By either confirming that this is a bug or by pointing out a user-induced problem or misunderstanding.

            Cheers,
            Ferdinand

            MAXON SDK Specialist
            developers.maxon.net

            1 Reply Last reply Reply Quote 0
            • P
              paula.kokic
              last edited by

              Hello @ferdinand ,

              I understand, of course. However, it's hard for me to give any code samples, not just because of privacy, but also because it's a really complex process we're doing in 5000+ lines of code in 4 Plugins that work together. Therefore, even trying to isolate/simplify something and send you the code and scene that you could test out yourself is quite impossible. And I really don't wanna waste your time by sending you the whole project and asking you for debugging.

              In any case - thank you very much again for your engagement, I highly appreciate it! I have a workaround for now and might take a closer look at this another time. We can mark the topic as "solved" 🙂

              Best Regards,
              Paula

              1 Reply Last reply Reply Quote 0
              • ferdinandF
                ferdinand
                last edited by

                Hello Paula,

                of course, I understand these restrictions, but on the other hand it is in this case hard to just guess the problem. Feel free to reopen this subject at any time.

                Cheers,
                Ferdinand

                MAXON SDK Specialist
                developers.maxon.net

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