R21 Script question


#1

In R20 I downloaded some scripts to toggle filters. (camera, grid, light, etc.)
The scripts don’t work in R21 anymore.
What is wrong with it?

import c4d
from c4d import gui

def main():
c4d.CallCommand(70000, 911) # Camera

if name==‘main’:
main()


#2

I guess the IDs in CallCommand may have changed, or the command has changed, or you messed up the indentations, or whatever. In general, using CallCommand() is only second choice because it’s hard to read, difficult to keep track of, and unfathomable in finding bugs…

Here is a script that uses standard functionality to toggle the Camera filter of the current viewport:

import c4d
from c4d import gui


def main():
    bd = doc.GetActiveBaseDraw()
    if bd == None :
        print "No BaseDraw!"
        return
    displayFilter = bd.GetDisplayFilter()
    if displayFilter & c4d.DISPLAYFILTER_CAMERA:
        bd[c4d.BASEDRAW_DISPLAYFILTER_CAMERA] = False
        print "Grid off!"
    else :
        bd[c4d.BASEDRAW_DISPLAYFILTER_CAMERA] = True
        print "Grid on!"
    bd.Message(c4d.MSG_CHANGE)
    c4d.EventAdd()

if __name__=='__main__':
    main()

Incidentally, I have just started a C4D API Python programming series on my ARFFA Patreon. Starting October 7th with episode (00):


Many posts there (duh, currently all) are open for all visitors, but as the effort put into that series depends on patrons, I would not mind if people decide to support :slight_smile:


#3

Thanks a lot Cairyn.