Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    Set Edge Selection Tag

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 1.4k Views
    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.
    • H Offline
      Helper
      last edited by

      On 23/04/2018 at 10:18, xxxxxxxx wrote:

      I have an Object plugin (a generator) in which I want to make and set a Selection Tag with the current edge selection of the active object.

      Edges are set, but not the correct ones. What is wrong?

      Here the code.

      import c4d
      from c4d import gui, utils
        
      def main() :
          selected = op.GetEdgeS() # Returns a BaseSelect that'll tell us which edges are currently selected
        
          nbr = utils.Neighbor()          
          nbr.Init(op)              
          nrEdges = nbr.GetEdgeCount()
          
          tag = op.MakeTag(c4d.Tedgeselection)	#create edge selection tag
          tag_baseSelect = tag.GetBaseSelect()
          tag_baseSelect.SelectAll(nrEdges-1) 
          
          for i in range(nrEdges) : # For every edge index of the object...    
              if selected.IsSelected(i) : # if it's selected...
                  tag_baseSelect.Select(i) # reflect that in the selection tag.
                  
          c4d.EventAdd()
      if __name__=='__main__':
          main()
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 24/04/2018 at 02:24, xxxxxxxx wrote:

        I guess I do not fully understand how edges are stored.
        I also I guess it has something to do with unique edges.
        When I select one edge of a cube and I run below script, it tells me 2 edges are selected.

        It looks like the edges are defined a-b and b-a.

        So, how to get and set unique edges?

            selected = op.GetEdgeS() # Returns a BaseSelect that'll tell us which edges are currently selected
            print "Selected: ", selected.GetCount()
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 24/04/2018 at 02:29, xxxxxxxx wrote:

          Hi Pim,

          Do you want to create an edge selection tag from a generator based on an active object? This would be a strange workflow.

          About the posted script, a BaseSelect content can be copied to another with the function CopyTo(). So there's no need to use Neighbor, a loop etc.
          (The error in your code is all edges are selected before the loop.)

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 24/04/2018 at 02:30, xxxxxxxx wrote:

            Ok, getting unique edges is working when using Neigbor()

                nbr = c4d.utils.Neighbor()          
                nbr.Init(op) 
                   
                edgeSelection = op.GetSelectedEdges(nbr, c4d.EDGESELECTIONTYPE_SELECTION)
                print edgeSelection.GetCount()
            

            Still have to figure out how to set the selection in the selection tag.

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              On 24/04/2018 at 02:40, xxxxxxxx wrote:

              Ah, so simple.
              Thank you.

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