Get the polycount of the scene [SOLVED]



  • On 27/09/2016 at 04:56, xxxxxxxx wrote:

    Hi guys,

    If I open the Project information windows (Ctrl+i) or (cmd+i)
    I get the number of polygons in the scene.

    How can I access this variable in python.

    I tried to PolygonObject.GetPolygonCount() but it seems to work just on Polygons object (since it's the polygon class).

    do there is any function returning that?

    Thanks



  • On 28/09/2016 at 06:48, xxxxxxxx wrote:

    Hi Augment, thanks for writing us.

    With reference to your request, we confirm that in order to retrieve the total number of polygons for the items present in your scene the preferable way is to traverse the scene and sum up the polygons count for the encountered PolygonObject derived instances.
    With reference to the polygons belonging to object generators it's recommended  to look through the objects cache and deform cache for the "tessellated" representation of the procedural item.
     
    Best, Riccardo



  • On 06/10/2016 at 05:58, xxxxxxxx wrote:

    Hi Augment,

    just a small additional hint.
    With cmd+I and Subdivision Surfaces within your scene, it seems that you´ll receive both, the generators polycount and the polycount of the object driving the generator.
    Furthermore the editors subdivisionlevel and not the render level is taken into account.

    Polygonizing the document might be a good way to receive the accurate number of polygons.

      
    import c4d  
      
    def polyOp(obj) :  
        
      result = []  
       
      while obj:  
            
          if obj.GetDown() :             
              result += polyOp(obj.GetDown())  
                  
          if obj.CheckType(c4d.Opolygon) :  
              count = obj.GetPolygonCount()  
                
              try:    
                  result[0] = [result[0][0] + count]  
              except:                 
                  result.append([count])  
                    
                    
          obj = obj.GetNext()  
                
      
      return  result  
      
    def main() :  
      doc = c4d.documents.GetActiveDocument()  
      doc2 = doc.Polygonize()  
      print polyOp(doc2.GetFirstObject())[0][0]  
      c4d.documents.KillDocument(doc2)  
      
    if __name__=='__main__':  
      main()  
      
    

    best wishes
    Martin



  • On 06/10/2016 at 10:53, xxxxxxxx wrote:

    sorry I´m a bit rusty.
    messed up the loop...
    That one should work well:

      
    import c4d  
      
    def GetNextObject(obj) :  
      
      if obj==None:  
          return None    
      if obj.GetDown() :  
          return obj.GetDown()    
      while not obj.GetNext() and obj.GetUp() :  
          obj = obj.GetUp()    
      return obj.GetNext()  
      
    def IterateHierarchy(obj) :  
            
      if obj is None:  
          return       
      pcounter = 0    
      while obj:          
          if obj.CheckType(c4d.Opolygon) :  
              pcounter += obj.GetPolygonCount()            
          obj = GetNextObject(obj)                   
      return pcounter  
      
    def main() :  
        
      doc = c4d.documents.GetActiveDocument()      
      doc2 = doc.Polygonize()  
      first = doc2.GetFirstObject()   
      if first == None:return  
      print IterateHierarchy(first)  
        
      c4d.documents.KillDocument(doc2)  
        
    if __name__=='__main__':  
      main()  
      
    


  • On 12/10/2016 at 07:40, xxxxxxxx wrote:

    thanks a lot for your reply guys,
    I wanted to avoid the "Polygonizing" Process.

    But it's exactly what I needed thanks a lot so I'll do it that way:)



  • On 14/10/2016 at 00:36, xxxxxxxx wrote:

    Hi Yohann,

    beware that "Polygonizing" can be avoided if polygon data from the cache or the deform cache are properly retrieved. Please have a look at GetCache() and here GetDeformCache() for further info .

    Best, R.


Log in to reply