Python - How to insert knots in c4d.Gradient
-
Hello everyone!
I'm trying to add knots to the c4d.Gradient object, in GvNode. But the changes are not applied to the parameter, maybe I missed something, and this parameter needs to be updated?import c4d import redshift knots = [ (c4d.Vector(1,0,1), 0.25, 0.25, 0.25), (c4d.Vector(0,1,1), 0.5, 0.5, 0.5), (c4d.Vector(1,1,0), 0.75, 0.75, 0.75), ] def main() -> None: rs_material = doc.GetActiveMaterial() if not rs_material.GetTypeName() == "RS Shader Graph": print(rs_material.GetTypeName()) return # Get node master and root nm = redshift.GetRSMaterialNodeMaster(rs_material) root = nm.GetRoot() # Create RSRamp gvNode ramp_node = nm.CreateNode(root, 1036227) ramp_node[c4d.GV_REDSHIFT_SHADER_META_CLASSNAME] = 'RSRamp' # Get Gradient gradient = ramp_node[c4d.REDSHIFT_SHADER_RSRAMP_RAMP] gradient.FlushKnots() for i, knot in enumerate(knots): gradient.InsertKnot(knot[0], knot[1], knot[2], knot[3], i ) # Check values for i in range(gradient.GetKnotCount()): knot = gradient.GetKnot(i) col = knot.get("col") pos = knot.get("pos") br = knot.get('brightness') print(f"col = {col}, pos = {pos}, brightness = {br} ") main()
-
Welcome to the Maxon developers forum and its community, it is great to have you with us!
Getting Started
Before creating your next postings, we would recommend making yourself accustomed with our forum and support procedures. You did not do anything wrong, we point all new users to these rules.
- Forum Overview: Provides a broad overview of the fundamental structure and rules of this forum, such as the purpose of the different sub-forums or the fact that we will ban users who engage in hate speech or harassment.
- Support Procedures: Provides a more in detail overview of how we provide technical support for APIs here. This topic will tell you how to ask good questions and limits of our technical support.
- Forum Features: Provides an overview of the technical features of this forum, such as Markdown markup or file uploads.
It is strongly recommended to read the first two topics carefully, especially the section Support Procedures: Asking Questions.
About your First Question
Custom datatypes implement copy constructor, which effectively means that at the line
gradient = ramp_node[c4d.REDSHIFT_SHADER_RSRAMP_RAMP]
you copy c4d.Gradient from the node and store it in variable 'gradient'. All further interactions are performed with this local copy of the gradient. In order to apply them back to the node you need to assign your local variable after modifications back to the node:
ramp_node[c4d.REDSHIFT_SHADER_RSRAMP_RAMP] = gradient
Cheers,
Ilia -
Thank you very much, @i_mazlov! This is what I needed!