Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Python Tag: Detecting Edge Selection Changes

    Cinema 4D SDK
    windows 2025 python
    2
    3
    452
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ymoonY
      ymoon
      last edited by

      Can Python tag detect when an object's edge selection is being added or modified?

      So far, this is the only thing I've discovered: The detection only responds when a component is added or deleted.

      import c4d
      def main():
          pass
      def message(mid, data):
          if mid == c4d.MSG_POLYGONS_CHANGED: 
              print(f"somthing is happening: {mid}")
          return True
      
      1 Reply Last reply Reply Quote 0
      • M
        m_adam
        last edited by

        Hey @ymoon addition and deletion are indeed reported with the MSG_POLYGON_CHANGED but this can be used also for other events like modification of the topology itself so it's not 100% reliable that you will have only edge selection information.
        The best way for you will be to store and detect the change yourself based on the dirty count of the BaseSelect the tag is storing. Find bellow a code example that you can copy-paste in a Python Tag that will report you modifications to all edge selections and also the "active one"

        import c4d
        
        # Dictionary to store tags and their dirty states
        tagsHash = {}
        # Variable to track the dirty state of active edge selection
        activeEdgeSelectionDirty = 0
        
        def GetEdgeSelectionDirty(tag):
            """
            Retrieves the dirty state of an edge selection tag.
        
            Parameters:
            tag (c4d.SelectionTag): The selection tag to check.
        
            Returns:
            int: The dirty state of the selection tag.
        
            Raises:
            TypeError: If the provided tag is not a selection tag.
            """
            if not isinstance(tag, c4d.SelectionTag):
                raise TypeError("Expected a selection tag")
        
            # Get the BaseSelect object from the selection tag
            bs = tag.GetBaseSelect()
            # Return the dirty state of the BaseSelect
            return bs.GetDirty()
        
        def main():
            """
            Main function to track and print changes in edge selection tags.
        
            This function checks all edge selection tags of the current object,
            compares their dirty states with stored values, and updates the state
            if there are changes. It also handles removed tags and prints changes
            in the active edge selection.
            """
            # List of tags that we did not visited in the current execution
            # We will use this list to determine which tags have been deleted.
            notVisitedTags = list(tagsHash.keys())
        
            # Get the object associated with the current operation
            obj = op.GetObject()
        
            # Iterate through all tags of the object
            for tag in obj.GetTags():
                if not tag.CheckType(c4d.Tedgeselection):
                    continue
        
                tagHash = hash(tag)  # Get a unique identifier for the tag
                if tagHash not in tagsHash:
                    # If the tag is new, store its dirty state
                    tagsHash[tagHash] = GetEdgeSelectionDirty(tag)
                    print(f"New Edge Selection Tag: {tag.GetName()}")
        
                else:
                    # If the tag has been seen before, remove it from not visited list
                    notVisitedTags.remove(tagHash)
        
                    # Check if the dirty state has changed
                    newDirty = GetEdgeSelectionDirty(tag)
                    if tagsHash[tagHash] != newDirty:
                        tagsHash[tagHash] = newDirty
                        print(f"Edge Selection Changed: {tag.GetName()}")
        
            # Process tags that are not visited anymore
            for removedTagHash in notVisitedTags:
                print(f"Edge Selection with the hash: {removedTagHash} removed")
        
            global activeEdgeSelectionDirty
            # Check if the active edge selection dirty state has changed
            newActiveEdgeSelectionDirty = obj.GetEdgeS().GetDirty()
            if activeEdgeSelectionDirty != newActiveEdgeSelectionDirty:
                activeEdgeSelectionDirty = newActiveEdgeSelectionDirty
                print("Active Edge selection changed")
        

        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 1
        • ymoonY
          ymoon
          last edited by

          Thanks, I'll test Dirty on selection.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post