Hi,
there are two different things here at play.
- Caches of objects are hierarchical (see docs). So when you want to evaluate the polygon count of your Python Generator Object (PGO) you haven to get the cache of the cube object returned by the cache of the PGO. Here is a little script that will spit out the cumulative polygon count of basically anything you throw at it.
import c4d
def get_cumlative_polygon_count(op):
""" Returns the cumlative polygon count of the passed node and its
descendants. Will also inspcect caches.
Args:
op (c4d.BaseObject): The node to evaluate the polygon count for.
Returns:
int: The cumlative polygon count of the passed node and its
descendants.
"""
if not isinstance(op, c4d.BaseObject):
return 0
# Op is not a polygon object, walk down the cache chain.
if not isinstance(op, c4d.PolygonObject):
cache = op.GetCache()
res = get_cumlative_polygon_count(cache) if cache else 0
# else get the polygon count
else:
res = op.GetPolygonCount()
# Evaluate the children
for child in op.GetChildren():
res += get_cumlative_polygon_count(child)
return res
def main():
"""
"""
print get_cumlative_polygon_count(op)
if __name__=='__main__':
main()
- Generator objects (e.g. a cube object) are recipes for generating objects, instantiating them does not produce any geometry. If you want to evaluate the output of a generator you have to add it to a document and execute its passes (or specifically the cache pass). As an example for your scenario:
import c4d
# Welcome to the world of Python
def get_cumlative_polygon_count(op):
""" Returns the cumlative polygon count of the passed node and its
descendants. Will also inspcect caches.
Args:
op (c4d.BaseObject): The node to evaluate the polygon count for.
Returns:
int: The cumlative polygon count of the passed node and its
descendants.
"""
if not isinstance(op, c4d.BaseObject):
return 0
# Op is not a polygon object, walk down the cache chain.
if not isinstance(op, c4d.PolygonObject):
cache = op.GetCache()
res = get_cumlative_polygon_count(cache) if cache else 0
# else get the polygon count
else:
res = op.GetPolygonCount()
# Evaluate the children
for child in op.GetChildren():
res += get_cumlative_polygon_count(child)
return res
def main():
"""
"""
cube = c4d.BaseObject(c4d.Ocube)
msg = "Cube polygon count before document execution:"
print msg, get_cumlative_polygon_count(cube)
temp_doc = c4d.documents.BaseDocument()
temp_doc.InsertObject(cube)
temp_doc.ExecutePasses(bt=None, animation=False,
expressions=False, caches=True, flags=0)
msg = "Cube polygon count after document execution:"
print msg, get_cumlative_polygon_count(cube)
cube.Remove()
return cube
Cheers
zipit