Skip to content

Instantly share code, notes, and snippets.

@MikeUdin
Created May 12, 2022 11:52
Show Gist options
  • Save MikeUdin/d5e243ffc84ff7288dc623c56e0275ea to your computer and use it in GitHub Desktop.
Save MikeUdin/d5e243ffc84ff7288dc623c56e0275ea to your computer and use it in GitHub Desktop.
import c4d
from c4d import gui
# In this video let's talk how to create layers,
# apply it to objects and change it attributes with Cinema 4D Python SDK.
# Check out tutorial here:
# https://mikeudin.net/?p=8680
def GetFirstLayer(doc):
return doc.GetLayerObjectRoot().GetDown()
def main():
# Get the first document layer
fl = GetFirstLayer(doc)
if not fl:
gui.MessageDialog('No layers found!')
return
# Set layer data with Solo attribute, you can add any other attribute to the dict
# like a {'solo':True, 'visible':True,'color':c4d.Vector(1,1,1)}
new_layer_data = {'solo':True}
fl.SetLayerData(doc,new_layer_data)
# This isn't documented near SetLayerData, but you must call this method or C4D won't know to update the
# solo state of layers in the scene.
doc.ChangeNBit(c4d.NBIT_SOLO_LAYER, c4d.NBITCONTROL_SET)
# Let C4D know something has changed to trigger a redraw
c4d.EventAdd()
if __name__=='__main__':
c4d.CallCommand(13957) # Clear Console
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment