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

    Is it possible to change the mode of the Viewport without callcommands?

    Cinema 4D SDK
    r20 python
    2
    6
    949
    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.
    • JH23J
      JH23
      last edited by

      It required to make a change of the mode type of the Viewport, when doing it I wondered if there was any way to do the same function without using callcomands.
      Is it possible?

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

        Hello @jh23,

        Thank you for reaching out to us.

        A viewport in Cinema 4D is represented by the types BaseDraw and BaseView (the former is the more important type) and its inheritance chain is C4DAtom -> GeListNode -> BaseList2D -> BaseView -> BaseDraw. So, viewports are BaseList2D as most central enteties in the classic API and can be modified with paramater access, e.g., myNode[SOME_ID] = someValue. The IDs can be found in multiple ways as explained here. The BaseDraw symbols can be found here here.

        It is not fully clear to me what you mean by the "mode type" of a viewport. I have provided a small example script which demonstrates some likely candidates.

        Cheers,
        Ferdinand

        The result:
        set_viewport_shading.gif

        The code:

        """Simple example that modifies all the viewports of a document.
        """
        
        import c4d
        
        def main(doc: c4d.documents.BaseDocument):
            """Modifies all viewports of the passed document #doc.
            """
            # Iterate over all 'BaseDraw' instances, i.e., viewports of the document. There are also
            # specific methods to retrieve the active or render BaseDraw of a document. See the Python 
            # BaseDocument documenation for details.
            for viewPort in (doc.GetBaseDraw(i) for i in range(doc.GetBaseDrawCount())):
                # A BaseDraw is a C4DAtom -> GeListNode -> BaseList2D as any other node in Cinema 4D and
                # almost all of its attributes are expressed as paramters which can be read and written.
                # The parameters can be discovered as usual with the console or Python documentation.
        
                print (f"{viewPort.GetName()}: {viewPort}")
        
                # Set the shading mode to "Gouraud - Lines"
                viewPort[c4d.BASEDRAW_DATA_SDISPLAYACTIVE] = c4d.BASEDRAW_SDISPLAY_GOURAUD_WIRE
        
                # Set the wire mode to "Isoparms"
                viewPort[c4d.BASEDRAW_DATA_WDISPLAYACTIVE] = c4d.BASEDRAW_WDISPLAY_ISOPARMS
        
            # Add an update event for Cinema 4D.
            c4d.EventAdd()
        
        
        # Execute main()
        if __name__=='__main__':
            # #doc is predefined in a script as the active document.
            main(doc)
        

        MAXON SDK Specialist
        developers.maxon.net

        JH23J 1 Reply Last reply Reply Quote 1
        • JH23J
          JH23 @ferdinand
          last edited by JH23

          Hello @ferdinand ,
          Thanks for the explanation, but in my case I meant this:
          ae8d5e77-639c-4352-a081-609a672165dd-image.png
          I need to make changes to these options, although it is true that they can be done by callcomands, I am interested in knowing if it is possible to avoid their use, I did some research, but didn't find much, I guess it's possible, and I probably didn't understand.
          still thank you very much for your contribution

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

            Hello @jh23,

            the editor mode of a document can be set with BaseDocument.SetMode and read with its counterpart BaseDocument.GetMode().

            Cheers,
            Ferdinand

            import c4d
            
            def main():
                """Toggle the document between point and polygon mode.
                """
                if doc.GetMode() == c4d.Mpoints:
                    doc.SetMode(c4d.Mpolygons)
                else:
                    doc.SetMode(c4d.Mpoints)
                    
                c4d.EventAdd()
            
            # Execute main()
            if __name__=='__main__':
                main()
            

            MAXON SDK Specialist
            developers.maxon.net

            JH23J 1 Reply Last reply Reply Quote 1
            • JH23J
              JH23 @ferdinand
              last edited by JH23

              Hello @ferdinand
              Thank you very much, I had no idea about that, I did know that Mpoints or Mpolygons existed, but it always related to me with ViewportSelect, this answers my question, I will investigate more about this.

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

                Hello @JH23,

                without any further questions and other postings, we will consider this topic as solved and flag it as such by Friday, 17/06/2022.

                Thank you for your understanding,
                Ferdinand

                MAXON SDK Specialist
                developers.maxon.net

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