SOLVED Setting Parameters from JSON File

Hi,

I'm trying to set parameters from a json file but it gives an error of TypeError: GeListNode_ass_subscript expected Description identifier, not str . How do I convert an str data to GeListNode_ass_subscript ?

Thank you for looking at my problem

Here's the working code:

import c4d
# Description: Adds a tag to a selected object


# This default parameter sets the dynamics tag to a collider tag.
# Assume this is from an external JSON file hence all strings and integers
default_param = {
    "collider_body": {
        "alt": "Standard",
        "shift": "Standard",  
        "param": {
            "[c4d.RIGID_BODY_DYNAMIC]": 0, 
            "[c4d.RIGID_BODY_RESTITUTION]": 1,
            "[c4d.RIGID_BODY_FRICTION]": 1,
        }
    }
}

def main():
    
    tag_type = 180000102
    tag_name = "collider_body"

    tag = op.MakeTag(tag_type)
    doc.AddUndo(c4d.UNDOTYPE_NEW, tag)

    param_dict = default_param[tag_name]['param']
    for key, value in param_dict.items():
        # Gives an error of TypeError: GeListNode_ass_subscript expected Description identifier, not str
        tag[key] = value #This should be equivalent as tag[c4d.RIGID_BODY_DYNAMIC] = 0/False,
        
    c4d.EventAdd()

# Execute main()
if __name__=='__main__':
    main()

Hi, the main issue is that the key is a string ad not either a descId or an integer.
So either you have to evaluate this either you can use getattr to retrieve the parameter like so.

keyId = getattr(c4d, "RIGID_BODY_DYNAMIC", None)
if keyId is None:
    return False
tag[keyId] = value

Cheers,
Maxime.

@m_adam

Thanks! Works as expected!