Jump to content

Sign in to follow this  
Myosis

Removing empty selection tags

Recommended Posts

I am trying to remove empty polygon selection tags using python.
It doesn't sound hard but I’m not getting anywhere, does anyone knows how to do it?

 

Share this post


Link to post
Share on other sites

Where do you have issues? Can you post your current code?

Share this post


Link to post
Share on other sites
  • Topic Author
  • @Cairyn

    Thanks for the response.

    That's the thing, I’m not even sure how to tackle this:

    import c4d
    
    def iter_hierarchy(op):
        for tag in op.GetTags():
            
    
            if tag.CheckType(c4d.Tpolygonselection) and not [ something here that says there are 0 polygons or points, or when size is 0 ?]:
    
                doc.AddUndo(c4d.UNDOTYPE_DELETE, tag)
                tag.Remove()
    
        for child in op.GetChildren():
            iter_hierarchy(child)
    
    def main():
    
        for op in doc.GetObjects():
            iter_hierarchy(op)
            
        c4d.EventAdd()
    
    main()


    But it would probably look something like this ?

    Let me know if you have a solution 🙂 
     


     

    Share this post


    Link to post
    Share on other sites

    That should be simple, as you have identified the tags already. Just cast to a SelectionTag. The SelectionTag has a method GetBaseSelect() which will give you the actual selection. From that BaseSelect you can extract the number with GetCount().

     

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • @Cairyn

    That sounds interesting! Not that experienced yet, but will try to puzzle a bit more with the info you gave me, thanks 🙂

    Share this post


    Link to post
    Share on other sites

    Just if you're interested, I have started a tutorial series on my Patreon yesterday: Python: Spoonfed.

    https://www.patreon.com/cairyn

    At the moment it's handling very basic stuff that you are maybe beyond already, but perhaps this will be of interest later on. Feel free to join.

     

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • 1 hour ago, Cairyn said:

    That should be simple, as you have identified the tags already. Just cast to a SelectionTag. The SelectionTag has a method GetBaseSelect() which will give you the actual selection. From that BaseSelect you can extract the number with GetCount().

     

    @Cairyn

    Is it possible you could show me an example of how to implement this in a small script ?
    I managed to see the poly count in the console with your advice:

    tagselection  =  tag.GetBaseSelect()
    tagselection.GetCount()
    print tagselection.GetCount()

    But I'm not sure how to continue the script if it reads 0
     

    Share this post


    Link to post
    Share on other sites
    28 minutes ago, Myosis said:

    But I'm not sure how to continue the script if it reads 0

    Then you remove the tag? I'm not sure what you are missing, as the removal was already in your original script.

    As you handle your iteration as Python list (instead of using the GetNext() / GetDown() functions), you should not have issues with pointers either.

     

    Only thing I see in your code is that you don't seem to call StartUndo() / EndUndo(), which is needed for a proper undo definition.

     

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • @Cairyn

    Yes if the GetCount is 0 I would like to remove the tag
    But I can't figure out how to write that particular line 


     

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • It should be something like this? 

        for tag in op.GetTags():
    
            if tag.CheckType(c4d.Tpolygonselection):
                tagselection  =  tag.GetBaseSelect()
                tagselection.GetCount()
                print tagselection.GetCount()
                if tagselection.GetCount()>= 0:
                    doc.AddUndo(c4d.UNDOTYPE_DELETE, tag)
                    tag.Remove()
                
                else:
                    return

    Again I'm not very experienced. At the moment its removing all tags. 

    It isn't reading the 0 part properly?

    Share this post


    Link to post
    Share on other sites

    Wouldn't you want the GetCount to be = to zero only, and not also greater than zero in order to pass to removal?

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • Oops faceplam, thank you!

    Works perfect now, super happy

    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...