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

    How to SetKeyframeSelection for Subfield

    Cinema 4D SDK
    2024 python
    2
    5
    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.
    • F
      freeter_e
      last edited by

      Hello,
      I want to know how to SetKeyframeSelection for subfield
      1.jpg

      here is my code

      import c4d
      
      def main():
      
          fields = op[c4d.FIELDS]
          first_layer = fields.GetLayersRoot().GetFirst() 
          first_layer_UniqueID = first_layer.GetUniqueID()
          print (f"first_layer_name: {first_layer.GetName()},  UniqueID: {first_layer_UniqueID}" )
      
          subfield = first_layer[c4d.FIELDLAYER_PROXIMITY_FIELDS]
          subfield_first_layer = subfield.GetLayersRoot().GetFirst() 
          subfield_first_layer_UniqueID = subfield_first_layer.GetUniqueID()
          print (f"subfield_first_layer_name: {subfield_first_layer.GetName()},  UniqueID: {subfield_first_layer_UniqueID}" )
      
      
          parameter_id = 440000260  #layer opacity
          op.SetKeyframeSelection([c4d.FIELDS , subfield_first_layer_UniqueID , parameter_id],True)   #<---- I don't know how to write it for subfield
          #op.SetKeyframeSelection([c4d.FIELDLAYER_PROXIMITY_FIELDS , subfield_first_layer_UniqueID , parameter_id],True)
      
      
      if __name__ == '__main__':
          main()
          c4d.EventAdd()  
      
      i_mazlovI 1 Reply Last reply Reply Quote 0
      • i_mazlovI
        i_mazlov @freeter_e
        last edited by

        Hi @freeter_e,

        FieldLists in our API can be a little tricky to work with. Luckily we have lots of nice discussions here on the forum on this topic.

        First of all, please have a look at this thread: Iterating through Field List, where Ferdinand provided great code snippet on how you can access field layers and the underlying objects that are linked to them.

        Secondly, the "Blending" category of the FieldLayers is a little special as it's a description of the FieldLayer object (not the corresponding linked BaseList2D object). You can find the corrseponding IDs for this description in our docs: Layer Controls

        For using SetKeyframeSelection function in this scenario you'd need to create correct c4d.DescID to access the opacity attribute from within the effector object:

        solidLayer: c4d.FieldLayer = ...  # search for the field layer, subfield_first_layer in your code example
        level1 = c4d.DescLevel(c4d.FIELDS)
        level2 = c4d.DescLevel(solidLayer.GetUniqueID())
        level3 = c4d.DescLevel(c4d.ID_FIELDLAYER_STRENGTH)
        op.SetKeyframeSelection(c4d.DescID(level1, level2, level3), True)
        

        Cheers,
        Ilia

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • F
          freeter_e
          last edited by

          Hello @i_mazlov
          Thanks for the reply, and the thoughtful extended reading.

          I used the code you provided, but it doesn't seem to change the results.

          i_mazlovI 1 Reply Last reply Reply Quote 0
          • i_mazlovI
            i_mazlov @freeter_e
            last edited by

            Hi @freeter_e,

            yes, you're right, the code I provided would work for simple hierarchies. However, things get complex when you need to access layers underneath modifier layer fields.

            In your scenario the Freeze field modifier is used, which makes the FieldLayer hierarchy quite complex, namely to access the solid field layer, you need to:

            1. find Freeze field layer in the field list of Plain effector
            2. access its FieldList using c4d.FIELDLAYER_PROXIMITY_FIELDS attribute
            3. repeat the search for the Solid field layer in the Freeze's field list.

            Unfortunately, here we see some limitation of the Python implementation, namely the Keyframe selection information is handled in a special way, so you can only adjust it as long as you can access it from the "real" object (like the Plain effector). However, with the "virtual" objects like modifier field layers, you cannot access their children from the effector object (because you need to first retrieve their own FieldList). Hence, any modifications you apply to its keyframe selection attribute will not be saved to the actual object on the scene. Please note, this is only the case for the keyframe selection, ordinary attribute values are properly handled.

            This actually means that you can not achieve this using our Python API. From my understanding of the issue, our C++ API does not have this flaw, so you can consider switching to C++ in case you actually need this functionality.

            Cheers,
            Ilia

            MAXON SDK Specialist
            developers.maxon.net

            1 Reply Last reply Reply Quote 0
            • F
              freeter_e
              last edited by

              Thanks again.@i_mazlov
              I haven't studied C++ yet, but I'm glad to know that it's achievable with C++.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post