Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Setting Parameters from JSON File

    Cinema 4D SDK
    r21 python
    2
    3
    782
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      bentraje
      last edited by bentraje

      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()
      
      1 Reply Last reply Reply Quote 0
      • M
        m_adam
        last edited by

        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.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 3
        • B
          bentraje
          last edited by

          @m_adam

          Thanks! Works as expected!

          1 Reply Last reply Reply Quote 0
          • John_DoJ John_Do referenced this topic on
          • First post
            Last post