Toggle Viewport Solo On/Off with a script


#1

Hi,

By default, you’d have to go on two keys. One is to enable it and the other to turn it off.
I would like to have it in one script. Where it goes like this

(1) Determine if viewport solo is turn on;
(2) if it is, turn it off.
(3) else, turn it on.

The problem I have is I can’t find the command in Python documentation. The script console gives me this:


    c4d.CallCommand(431000059, 431000059) # Viewport Solo Single
    c4d.CallCommand(431000058, 431000058) # Viewport Solo Off

I cannot find the command 431000059 and 431000058 in the python documentation.
Is there a way around this?

Thank you.


#2

Use Nitroman’s free Magic Solo plugin instead, and map that to a keyboard shortcut? I can’t live without that thing. So such better than default C4D solo.


#3

Thanks for the response Luke. But this is also scripting learning experience for me. So, the script format would really be helpful.


#4

What you’re looking for is the command “IsCommandChecked” which tests whether a command is currently checked (duh!)
This will enable you to tell the state and trigger the on/off commands accordingly.


import c4d
from c4d import gui

def main():
    if c4d.IsCommandChecked(431000061) :
        print "Solo Selection is on" # just for information

    if c4d.IsCommandChecked(431000059) :
        print "Solo Single is on"
        c4d.CallCommand(431000058)  # Viewport Solo Off
    else :
        print "Solo is not on"
        c4d.CallCommand(431000059)  # switch it on
            
if __name__=='__main__':
    main()

Handle Viewport Solo Hierarchy as needed.


#5

Hi Cairyn,

Your script works. Thank you very much.

May I ask if there is a catalogue/listing for the command numbers in C4D? I can’t seem to find them.

Thank you.


#6

The Customize Command dialog shows the IDs when you select the command.


#7

Not really, magic solo also disables all xparticle emitters everytime you use it on any object in the scene


#8

Thanks for the response!