SOLVED How to just open a certain window instead of toggling

Hi,

I want to write a script that opens a certain window when executed, but when I use CallCommand(), it closes the window that is already open.
Is there any way to open that window when it is not open and do nothing when it is already open?

Any help would be greatly appreciated.

Hello @kng_ito,

Thank you for reaching out to us. You have deleted this topic, which likely means that you found the solution yourself. This question has been answered before and you likely found one of these answers, but I think it does not hurt to answer this again, especially since I already wrote the answer and then sat in a never ending meeting 🙂 In general, we also prefer topics not to be deleted, but rather have them pointing to the correct solution, so that future readers will find solutions over multiple search entries.

Answer

This can be solved in this specific case with c4d.IsCommandChecked. I have provided an example at the end of the posting. A related subject is GeDialog folding and opening for dialogs a user has implemented; an example for that can be found here.

Cheers,
Ferdinand

"""Example for opening the Material Manger.

Run this script as a Script Manger script, it will only open the Material Manager, but not close
it by executing the command twice.

Using c4d.IsCommandChecked allows to execute commands only when they indicate to not already be 
running. In the case of commands which open some form of dialog, this means that the command is
only executed when the dialog is not already open. This requires the CommandData plugin hook to
implement CommandData.GetState() to return its state.
"""

import c4d

IDM_MATERIAL_MANAGER: int = 12159

def main() -> None:
    # When the Material Manager command indicates not to be already running, invoke its command.
    if not c4d.IsCommandChecked(IDM_MATERIAL_MANAGER):
        c4d.CallCommand(IDM_MATERIAL_MANAGER)
    
    
if __name__ == '__main__':
    main()

Hello @kng_ito,

Thank you for reaching out to us. You have deleted this topic, which likely means that you found the solution yourself. This question has been answered before and you likely found one of these answers, but I think it does not hurt to answer this again, especially since I already wrote the answer and then sat in a never ending meeting 🙂 In general, we also prefer topics not to be deleted, but rather have them pointing to the correct solution, so that future readers will find solutions over multiple search entries.

Answer

This can be solved in this specific case with c4d.IsCommandChecked. I have provided an example at the end of the posting. A related subject is GeDialog folding and opening for dialogs a user has implemented; an example for that can be found here.

Cheers,
Ferdinand

"""Example for opening the Material Manger.

Run this script as a Script Manger script, it will only open the Material Manager, but not close
it by executing the command twice.

Using c4d.IsCommandChecked allows to execute commands only when they indicate to not already be 
running. In the case of commands which open some form of dialog, this means that the command is
only executed when the dialog is not already open. This requires the CommandData plugin hook to
implement CommandData.GetState() to return its state.
"""

import c4d

IDM_MATERIAL_MANAGER: int = 12159

def main() -> None:
    # When the Material Manager command indicates not to be already running, invoke its command.
    if not c4d.IsCommandChecked(IDM_MATERIAL_MANAGER):
        c4d.CallCommand(IDM_MATERIAL_MANAGER)
    
    
if __name__ == '__main__':
    main()

Hi @ferdinand,

I deleted my original post because I realized the question contained my misunderstanding.
And now your answer has completely solved the problem I had.

Thank you very much for your detailed response!