Re: Fieldlist HasContent() GetCount() bug workaround
Hello guys!
I think i've found the solution how to fix FieldsLists with "ghost" layers (without linked FieldObjects, deleted in OM). I want to apply it to fix my ObjectPlugin FieldLists but i do not know how to make it securely. Maybe after each object deletion in Cinema 4D scene? How to implement this? There better solution?
Here is a code that works for me:
def get_field_layers(op):
"""
Returns all field layers that are referenced in a field list.
Source: https://plugincafe.maxon.net/topic/11809/iterating-trough-field-list/2?_=1678357010902
"""
def flatten_tree(node):
""" Listifies a GeListNode tree. """
r = []
while node:
r.append(node)
for child in node.GetChildren():
r += flatten_tree(child)
node = node.GetNext()
return r
# get the GeListHead for the FieldList
root = op.GetLayersRoot()
if root is None:
return []
# Get the first node under the GeListHead
first = root.GetFirst()
if first is None:
return []
# traverse the graph
return flatten_tree(first)
def CleanUpFieldListDeadLayers(doc, fieldlist):
for f in get_field_layers(fieldlist):
if f.CheckType(c4d.FLfield) and not f.GetLinkedObject(doc):
f.Remove()
return fieldlist
def main():
fixed_fieldlist = CleanUpFieldListDeadLayers(doc,op[c4d.MYPLUGIN_FIELDLIST])
op[c4d.MYPLUGIN_FIELDLIST] = fixed_fieldlist
if __name__ == '__main__':
main()