BaseSelect.GetAll() is confusing



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 17/08/2011 at 15:42, xxxxxxxx wrote:

    I'm trying to make a script that will make any selected polygons double-faced (i.e two polygons created on the same set of points). This is useful for certain models for games (e.g. thin objects like butterfly wings etc).

    Anyway, the first step is to get the polygons that have been selected. So I used GetPolygonS() which gives you a BaseSelect object and then GetAll() which is supposed to return a list of the selected polygons. However, for me the results are odd.

    Here is the code so far.

    _import c4d
    from c4d import gui
    from c4d import documents
    from c4d import BaseSelect
    #Welcome to the world of Python

    def main() :
      doc = documents.GetActiveDocument()
      objects = doc.GetActiveObjects(False)
      numObjects = len(objects)
      #print numObjects
      if numObjects > 0:
          obj = doc.GetActiveObject()
          if type(obj) == c4d.PolygonObject:
              #First we get the selected polygons
              selectedPolys = obj.GetPolygonS()
              print selectedPolys.GetCount(), "Selected Polygons are..."
              print selectedPolys.GetAll(selectedPolys.GetCount())
             
          else:
              gui.MessageDialog('Object is not a polygon object. Make it editible!')
             
      else:
          gui.MessageDialog('No objects were selected')
     
      return True

    if __name__=='_main__':
      main()

    If I create a plane with 4 quads, make it editable and select all faces, the results of printing GetAll() are as follows.

    4 Selected Polygons are
    [1,1,1,1]

    I was expecting that BaseSelect.GetAll() would return the indices of the polygons, and since there are 4 quads, I was expecting [0,1,2,3] for the results (although not necessarily in that order).

    Any ideas what I am doing wrong? Thanks in advance.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 18/08/2011 at 11:28, xxxxxxxx wrote:

    GetAll returns a list with boolean values (selected or not | 1 or 0).

      
    x = bs.GetAll()   
    if x[polygon_index]:   
      # polygon with index 'polygon_index' is selected
    

Log in to reply