Jump to content

Sign in to follow this  
gfunk

toggle visiblity of selected objects

Recommended Posts

Hello All

I had some c.o.f.f.e.e. scripts that I use to toggle the visibility of objects in c4d on and off.  but now that r20 doesn't like coffee my scripts no longer work.  I'm having trouble converting them to python since I'm not a scripter.  Can anyone help me. 

Here is the original coffee script

 

Hides in editor and in render

CallCommand(1016208); // Hide Objects
CallCommand(100004784); // Renderer Off

 

Resets object to visible in editor and visible in render

CallCommand(100004779); // Editor Unchanged
CallCommand(100004782); // Renderer Unchanged

 

These scripts just let me toggle selected objects to be hidden in the editor and renderer without having to toggle the dots.

 

I've tried to transfer this into python but I can't get it to work with multiple selected objects.  Can anyone help me.  Here is my python hack right now.

 

import c4d
from c4d import gui
#Welcome to the world of Python


def main():
    def object():
        return doc.GetActiveObject()
    obj = object()

    obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = 1
    obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = 1

if __name__=='__main__':
    main()
    c4d.EventAdd()
    
This hides the selected object.  But if I select multiple objects it doesn't work.  

Any help super appreciated.

Thanks


    

 

Share this post


Link to post
Share on other sites

This should work:

 

import c4d
from c4d import gui

def main():

    allobj = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
    obj = object()
    for obj in allobj:
        obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = 1
        obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = 1

if __name__=='__main__':
    main()
    c4d.EventAdd()

Share this post


Link to post
Share on other sites
  • Topic Author
  • That doesn't work.  If I copy and paste nothing happens when selecting one object or multiple objects. 

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • I got it working.  For some reason there was something weird when I copied it to the scripting window.  I deleted the

    if __name__='__main__':

    main()

     

    and rewrote it and the script is working.  Thanks so much!!!

    Share this post


    Link to post
    Share on other sites

    Welcome, glad it helped you!

    Share this post


    Link to post
    Share on other sites

    Hi!

     

    Would it be possible to add a toggle function (with an else function?) to allow turning it back on if it's already turned off? So ideally you can toggle on and off from the same script.

     

    Any help would be really appreciated!

     

    Share this post


    Link to post
    Share on other sites

    Following with that subject, I got some help and this is the result : 

     

    import c4d
    from c4d import gui

    def main():

        allobj = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
        obj = object()
        for obj in allobj:
            editor = obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR]
            render = obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER]
            
            if editor == 1 or render == 1:
                newstate = 2
            else:
                newstate = 1
                
            obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = newstate
            obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = newstate


    if __name__=='__main__':
        main()
        c4d.EventAdd()
       

    Share this post


    Link to post
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    Sign in to follow this  

    • Recently Browsing   0 members

      No registered users viewing this page.

    ×
    ×
    • Create New...