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

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?

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

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)

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

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

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.

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