Remove empty polygons


#1

I imported a 3D file with a lot of empty polygons.
How can I possibly delete them all at ones?


#2

this should do it (does not delete object, if children present, though):

import c4d
from c4d import documents as docs


class ObjIter:

    def __init__(self, obj):
        self.obj = obj
        self.currObj = obj
        self.objStack = []

    def __iter__(self):
        return self

    def __next__(self):

        if not self.currObj:
            raise StopIteration

        obj = self.currObj

        if self.currObj.GetDown():
            self.objStack.append(self.currObj.GetNext())
            self.currObj = self.currObj.GetDown()
        else:
            self.currObj = self.currObj.GetNext()
            while not self.currObj and len(self.objStack) > 0:
                self.currObj = self.objStack.pop()

        return obj


def main():
    doc = docs.GetActiveDocument()
    obj = doc.GetFirstObject()
    scene = ObjIter(obj)

    for obj in scene:
        if isinstance(obj, c4d.PolygonObject) and obj.GetPointCount() == 0 and not obj.GetDown():
            obj.Remove()
    c4d.EventAdd()


if __name__ == '__main__':
    main()

#3

Thanks for your help.
But unfortunately it doesn’t work.


#4

i am assuming you’re on a c4d-release >= 23 then (i believe the python-version change came with r23)?
i 've edited the code above, try again, see if it works.


#5

Exact I am on R26.
Used the script and deleted 400+ empty polygons.
This made my day.

Thanks a lot Mesutcakin.