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

    Face associated with a selection

    Cinema 4D SDK
    python
    3
    4
    639
    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.
    • KantroninK
      Kantronin
      last edited by Manuel

      Hi,

      I have a polygon with multiple selections.
      For each selection, I want to know the list of faces (presented as a list of indices)

      selection.jpg

      For a polygon I know how to access each selection:

      tag = polygone.GetFirstTag()
      while tag:
      	if tag.GetType() == c4d.Tpolygonselection:
      	print tag.GetName()
      	..
      	...
      	...
      	tag = tag.GetNext()
      

      If you can replace the dotted lines with the correct code, thanks

      1 Reply Last reply Reply Quote 0
      • CairynC
        Cairyn
        last edited by

        A SelectionTag (no matter what type the selection is) has a method GetBaseSelect which returns a (reference to the contained) c4d.BaseSelect object which in turn contains the needed functions:
        https://developers.maxon.net/docs/py/2023_2/modules/c4d/BaseSelect/index.html

        (You may want to have an eye on the API description which can answer these easy questions without the need to write an elaborate question 🙂 )

        1 Reply Last reply Reply Quote 0
        • ManuelM
          Manuel
          last edited by Manuel

          Hi,

          I think @Cairyn gave the correct answer. You must retrieve the BaseSelect of the tag.

          You may also want to read ou forum Guidelines where you can learn how to mark your thread as a question and set them as solved once it's done. Using the tags also help a lot for us to know which language you are using (if no code is provided).

          def main():
              tag = op.GetFirstTag()
              polyCount = op.GetPolygonCount()
              while tag:
                  if tag.GetType() == c4d.Tpolygonselection:
                      bs = tag.GetBaseSelect ()
                      states = bs.GetAll(polyCount)
                      print (states )
                      indices = (pid for pid, item in enumerate(states) if item)
                      print (indices)
                  tag = tag.GetNext()
          
          

          Cheers,
          Manuel

          MAXON SDK Specialist

          MAXON Registered Developer

          1 Reply Last reply Reply Quote 0
          • KantroninK
            Kantronin
            last edited by

            Thanks for your quick replies

            I used GetBaseSelect() which allowed me to have the selected faces for each selection

            		list_polygon = obj.GetAllPolygons() 
            		dim = len(list_polygon)
            
            		L = []
            		tag = obj.GetFirstTag()
            		while tag:
            			if tag.GetType() == c4d.Tpolygonselection:
            				sel = tag.GetBaseSelect()
            				L2 = []
            				for i in range(0,dim):
            					if sel.IsSelected(i):
            						L2.append(i)
            						
            				L.append([tag.GetName(),L2])
            			tag = tag.GetNext()	
            			
            		for item in L:
            			print item[0]
            			print item[1]
            
            1 Reply Last reply Reply Quote 0
            • First post
              Last post