Solved Cinema 4D 2023 None bug

A None report happened when modify Fieldlist in R 2023 , ss a bug or I missed something ?

More :

None report seems happened in R 2023 , It would work actually , but It report a bug like this :
The same code runs well in S26.107 without bug report :

Here is the code :

import c4d

def get_field_layers(op):
    """ Returns all field layers that are referenced in a field list.
    def flatten_tree(node):
        """ Listifies a GeListNode tree.
        res = []
        while node:
            for child in node.GetChildren():
                res += flatten_tree(child)
            node = node.GetNext()
        return res

    # 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 main():
    fieldlists = [value for id, value in op.GetData()
                  if isinstance(value, c4d.FieldList)]
    if not fieldlists:
    opname = op.GetName()
    for layer in get_field_layers(fieldlists[0]):
        obj = layer.GetLinkedObject(doc)
        obj.SetBit(c4d.BIT_ACTIVE) somethings
if __name__=='__main__':

Hello @dunhou,

thank you for reaching out to us. Thank you for the detailed report, a little tip though, when you provide error outputs (either as text dumps or as screenshots), or when you want to debug yourself, you should always make sure the script has been saved first. As only for a saved script you will get a stack trace which contains the actual line of code which failed (and not just its line number). Due to formatting errors, line numbers can be a bit ambiguous on the forum.

E.g., when you run the script without an object selected and without the script being saved, it will spit out the following because op is then None.

Traceback (most recent call last):
  File "scriptmanager", line 44, in <module>
  File "scriptmanager", line 30, in main
AttributeError: 'NoneType' object has no attribute 'GetData'

When you do the same with a saved script the stack trace will be:

Traceback (most recent call last):
  File "C:\Users\f_hoppe\AppData\Roaming\Maxon\2023.0.0_C4F8B542\library\scripts\untitled", line 44, in <module>
  File "C:\Users\f_hoppe\AppData\Roaming\Maxon\2023.0.0_C4F8B542\library\scripts\untitled", line 30, in main
    fieldlists = [value for id, value in op.GetData()
AttributeError: 'NoneType' object has no attribute 'GetData'

Which is quite a bit more informative, as you can see the actual line of code which failed.

About your Issue

From the context of things, I would assume it is doc.AddUndo(c4d.UNDOTYPE_CHANGE,obj) which is failing in your code because obj is None. The method FieldLayer.GetLinkedObject can return None because not all FieldLayer have a BaseObject representation. Or less technical: Not for every entry in a field list necessarily a matching object in the Object Manager can be found.

When I run your script on 'logical' inputs, i.e., an object with a field list containing a field list which only contains layers which each have an object, the script works fine for me. The problem only occurs when I add such 'unrepresented' layer type, e.g., a solid layer. So, you must simply check obj for being None or check the type of the field layer first before you try to get its linked object.

In case this does not solve the problem for you, I would have to ask you to share the scene/object on which you are running the script, because the setup of the field list matters here.


MAXON SDK Specialist


I Check with my home PC in R 2023, It works fine , And for some reason , It report a none last time I am pretty sure I have not insert a layer field in fieldlist ( I just miniest the scene for test code ) , But when I resart C4D today this none warning just gone:anguished:

Maybe It is just a oolong events I make some thing I don't know . Sorry for that .

And Thanks for the TIPS , next post I will take a more spesific report :face_with_cowboy_hat: