How to SetKeyframeSelection for Subfield
-
Hello,
I want to know how to SetKeyframeSelection for subfield
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()
-
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 -
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.
-
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:
- find Freeze field layer in the field list of Plain effector
- access its FieldList using c4d.FIELDLAYER_PROXIMITY_FIELDS attribute
- 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 -
Thanks again.@i_mazlov
I haven't studied C++ yet, but I'm glad to know that it's achievable with C++.