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

    Get the polycount of the scene [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    6 Posts 0 Posters 627 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 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

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

        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

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

          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

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

            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()  
              
            
            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              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:)

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

                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.

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