I want to use a Python script to animate a set of cubes (called parcels) using a given JSON dataset. I have previously written a script that works for this, with a set of 15 parcels. This script reads the data, and then generates cubes with different materials and keyframes accordingly. All parcels spawn on the same spot and have different paths to their end destinations.
For the sake of the animation, I want the parcels to fade in and out, meaning only one parcel should be visible at a time on the spawning spot. Once a parcel has reached its end destination, it should fade out.
I accomplished this by manually keyframing the RS material (which has been converted to a node material)'s geometry opacity V value in HSV. I did this manually because the number of parcels wasn't too large.
Now I want to do all of this with 100 parcels. Naturally, it's not effective or sustainable to manually keyframe 100 parcel's opacity. Thus, I want to implement this into the script. This is where I'm struggling.
In my script for 100 parcels, I've made a function called create_opacity_keyframe(obj, node_material, transparency_value, frame, interpolation=c4d.CINTERPOLATION_SPLINE). Here, I make sure the node material (the material applied to the parcel) has a node space, and I've found the node graph, root and ultimately the target node port for color opacity.
I get a ValueError when I try to create define the DescID for creating the keyframes. I have tried defining the DescID in two ways to try to debug:
# Ver 1
desc_id = node_material.GetDescIDForNodePort(spaceId, node, hsv_port)
# Ver 2
desc_id = c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_COLOR, c4d.DTYPE_VECTOR, 0))
In Ver 1, I have verified that the values of the passed arguments are valid, at least for the rest of the script, as they work correctly there. So I'm struggling to find out where this value error occurs.
I am also having the error: "Argument 1 must be c4d.BaseList2D not c4d.DescID" when trying to find the CTrack on the node material, even though I have previously verified that the node material is of the type BaseList2D:
track_opacity = node_material.FindCTrack(desc_id)
I am very familiar with Python in general but rather unfamiliar with scripting for C4D, and most definitely the use of the latest Maxon API with my 2025.1.0 version of C4D.
See the JSON dataset and script for my 15 parcels and 100 parcels respectively in this Drive folder (please ignore the fact that my scripts are a great spaghetti mess and NOT optimized or pretty at all; I focused on making things work sufficiently before optimizing and tidying up fully): https://drive.google.com/drive/folders/1E8RwytAWDjr-zI-EjPo5hNRI5th6MlgL?usp=drive_link