Hi @mia-elisenberg ,
If you want to add c4d.CKey
to a maxon.GraphNode
object, you need to:
- Get the BaseList2D of the node, in this case, the opacity is port, it is a
maxon.GraphNode
, you need to get his host object aka the true node, the Standard Surface BRDF node, also it is amaxon.GraphNode
. - Use the
GetBaseListForNode
to get thec4d.BaseList2D
- Get the port c4d.DescID
- Create track on the c4d.BaseList2D
BTW, you can find a topic which is a python library for renderers, in General Talk. I had added those methods but not pushed yet, will be pushed asap, you can take a look if needed.
Hope it helps.
Cheers~
DunHou
import c4d
import maxon
doc: c4d.documents.BaseDocument # The currently active document.
op: c4d.BaseObject | None # The primary selected object in `doc`. Can be `None`.
nodespaceId = "com.redshift3d.redshift4c4d.class.nodespace"
standardBRDF = "com.redshift3d.redshift4c4d.nodes.core.standardmaterial"
def main() -> None:
doc: c4d.documents.BaseDocument = c4d.documents.GetActiveDocument()
for material in doc.GetActiveMaterials():
nodeMaterial: c4d.NodeMaterial = material.GetNodeMaterialReference()
if not nodeMaterial.HasSpace(nodespaceId):
continue
graph: maxon.GraphModelInterface = nodeMaterial.GetGraph(nodespaceId)
nimbusRef: maxon.NimbusBaseRef = material.GetNimbusRef(nodespaceId)
result: list[maxon.GraphNode] = []
maxon.GraphModelHelper.FindNodesByAssetId(graph, standardBRDF, True, result)
if not result:
continue
# assume we just have one brdf node in this gragh
brdf_node: maxon.GraphNode = result[0]
opacityPort: maxon.GraphNode = brdf_node.GetInputs().FindChild('com.redshift3d.redshift4c4d.nodes.core.standardmaterial.opacity_color')
# try to find the BaseList2D for the node, this host on the true node in gragh
# 'opcacity' is a port, we have to get the host node: ie. the true node
parentNode: maxon.GraphNode = opacityPort.GetAncestor(maxon.NODE_KIND.NODE)
parentNodePath = parentNode.GetPath()
opacityPortBL2D: c4d.BaseList2D = nodeMaterial.GetBaseListForNode(nodespaceId, parentNodePath)
# create track and add key
opacityPortDescID: c4d.DescID = nimbusRef.GetDescID(opacityPort.GetPath())
track: c4d.CTrack = c4d.CTrack(opacityPortBL2D, opacityPortDescID)
opacityPortBL2D.InsertTrackSorted(track)
curve: c4d.CCurve = track.GetCurve()
key = c4d.CKey()
track.FillKey(doc, opacityPortBL2D, key)
ctime: c4d.BaseTime = c4d.BaseTime(doc.GetTime().GetFrame(doc.GetFps()), doc.GetFps())
key.SetValue(curve, 50.0)
key.SetTime(curve, ctime)
curve.InsertKey(key)
c4d.EventAdd()
if __name__ == '__main__':
main()