Jump to content

Python Script - Toggle Layer Solo View via Script


Go to solution Solved by Smolak,

Recommended Posts

Hi. 

 

Like the title already says, I want to create a small little script that toggles the Layer Solo view On / Off for a specific, pre-defined Layer name. I created a small script based on a tutorial from Mike Udin on YT and / or some stuff I already did in previous scripts and the script also works, at least the button gets toggled. But the viewport isn't updating. (even tried some Refresh commands at the end). Does someone already tried to create such a script? Because it should toggle our Vorlagen / Templates layer and sometimes it would be nice, if I could all the overlaying objects and only look at the template itself. 

 

Maybe I'm just missing some obvious additional line to make this work. At least I hope! 🙂 

 

import c4d
from pprint import pprint

def main():
    doc = c4d.documents.GetActiveDocument()
    layer_root = doc.GetLayerObjectRoot()
    vorlagen_layer = find_vorlagen_layer(layer_root)

    if vorlagen_layer:
        toggle_layer_solo(vorlagen_layer)
        c4d.EventAdd()

def find_vorlagen_layer(root):
    for layer in root.GetChildren():
        if "VORLAGEN" in layer.GetName():
            return layer
    return None

def toggle_layer_solo(layer):
    # source 
    # https://www.youtube.com/watch?app=desktop&v=Uboqi5jQDTU
    # Toggle the solo state
    # current_solo_state = layer[c4d.ID_LAYER_SOLO]
    # layer[c4d.ID_LAYER_SOLO] = not current_solo_state
    ld = layer.GetLayerData(doc)
    pprint(ld)
    new_ld = {'solo':True}
    ld = layer.SetLayerData(doc, new_ld)

    c4d.EventAdd()
    c4d.CallCommand(12147) # Update Screen

# Execute main()
if __name__ == '__main__':
    main()

 

Link to comment

This seems to work:

 

"""Name-en-US: Solo VORLAGEN Layer
Description-en-US: Toggle's the Vorlagen layer's Solo state.
"""

import c4d

def find_vorlagen_layer(root):
    # Warning: This will only work if "VORLAGEN" is a top-level layer
    # as we don't iterate the child layers.
    for layer in root.GetChildren():
        if "VORLAGEN" in layer.GetName():
            return layer
    return None

def toggle_layer_solo(layer):
    # source 
    # https://www.youtube.com/watch?app=desktop&v=Uboqi5jQDTU

    layer_data = layer.GetLayerData(doc)

    # Toggle the layer's Solo state.
    layer_data["solo"] = not layer_data["solo"]
    
    layer.SetLayerData(doc, layer_data)

    c4d.EventAdd()
    #c4d.CallCommand(12147) # Update Screen

def main():
    doc = c4d.documents.GetActiveDocument()
    layer_root = doc.GetLayerObjectRoot()
    vorlagen_layer = find_vorlagen_layer(layer_root)

    if vorlagen_layer:
        toggle_layer_solo(vorlagen_layer)
        c4d.EventAdd()

# Execute main()
if __name__ == '__main__':
    main()

 

Link to comment
  • Solution

If you want such feature only for fast layer switching you can always drag "solo mode" from chosen layer properties to viewport HUD and use this as layer solo button.

Link to comment

Unfortunately this doesn't work for me. The button gets toggled visually, but nothing happens on the screen. Tried it with C4D 2023 and 2024. 

 

And the alternative with dragging properties out to the HUD would also be an option for me, but I can't get anything grabbed related to the Solo View in the layers menu or with the Attributes - Modes - Layers? 

 

Maybe I'm doing something wrong with both of the suggestions or my Cinema is cursed. 😞

Link to comment
33 minutes ago, Smolak said:

 

Works fine :

solo_button.avi

 

Ah! That is a nice way to edit the HUD. I tried to add the button into my shelfs as a button. But this way will work too - just need to find the right position for it. 🙂 Thank you!

 

While I was trying out some things with that into-the-HUD stuff I found the button that lets me enable 'Render'. Do you know anything about that by any chance? Because if this text would be render'able like a stamp on the image, it would really help with the Look Dev if there are some parameters exposed into the image. Unfortunately I cant get it work. Not with the Standard / Physical render and of course not even with Corona render. 😞

Link to comment

Hi Smolak,

 

thanks for your ongoing support! 🙂 And thanks for the update / information about watermarks. While we're using Corona, I still managed to find the watermark settings for it. But it seems like the watermarks are still limited to the pre-configured ones with no chance to add custom watermark variables (like the Rotation value of the Corona Sun for example). 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • LATEST ACTIVITIES

    1. 1

      Cinema 4D 2025.1 ❄️ Winter Release 2024

    2. 1

      Cinema 4D 2025.1 ❄️ Winter Release 2024

    3. 13

      Multi Gizmo (Move, scale, rotate in one)

    4. 7

      Looking for Python Script : Create Instances from multiple Selected objects

    5. 13

      Multi Gizmo (Move, scale, rotate in one)

×
×
  • Create New...