Skip to content

Instantly share code, notes, and snippets.

@MikeUdin
Created June 26, 2017 12:35
Show Gist options
  • Save MikeUdin/d3c9fd3814ed48cfc02907210cd46b9b to your computer and use it in GitHub Desktop.
Save MikeUdin/d3c9fd3814ed48cfc02907210cd46b9b to your computer and use it in GitHub Desktop.
Toggle visibility of the selected objects in Cinema 4D scene
import c4d
# Toggle selected objects visibility in Editor and Renderer
# SHIFT - toggle visibility in Editor only
# CONTROL - toggle visibility in Renderer only
# Author: Mike Udin
# http://mikeudin.net
def main():
objs = doc.GetActiveObjects(1)
if not objs: return
values = (2,#Default
0,#On
1)#Off
bc = c4d.BaseContainer()
pars = None
if c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD,c4d.BFM_INPUT_CHANNEL,bc):
#901 - c4d.ID_BASEOBJECT_VISIBILITY_EDITOR
#902 - c4d.ID_BASEOBJECT_VISIBILITY_RENDER
if bc[c4d.BFM_INPUT_QUALIFIER] == 1:
pars = [901]
if bc[c4d.BFM_INPUT_QUALIFIER] == 2:
pars = [902]
if bc[c4d.BFM_INPUT_QUALIFIER] == 0:
pars = [901,902]
if not pars: return
for par in pars:
vals = set([o[par] for o in objs])
if len(vals) > 1:
for obj in objs:
obj[par] = 2
for obj in objs:
for p in pars:
for num,v in enumerate(values):
if v == obj[p]:
new_v = values[(num+1)%len(values)]
obj[p] = new_v
break
c4d.EventAdd()
if __name__=='__main__':
main()
@Mules75
Copy link

Mules75 commented Oct 31, 2022

OK, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment