Script to change parameters across all similar nodes material
-
Hi, I want to change all settings of thickness in Contour node of all toon materials?
Any idea of how to do this?
thanksimport c4d from c4d import gui def traverse_nodes(graph, ext_value, int_value): """Recursively search nodes in a graph.""" for node in graph.GetNodes(): try: node_id = node.GetDefinition().GetID() except: node_id = None # Look for the RS Contour node by its ID string if node_id == "com.redshift3d.redshift4c4d.nodes.core.contour": print(f"✅ Found Contour node in: {node.GetName()}") node.SetParameter("com.redshift3d.redshift4c4d.nodes.core.contour.externalthickness", ext_value, c4d.DESCFLAGS_SET_0) node.SetParameter("com.redshift3d.redshift4c4d.nodes.core.contour.internalthickness", int_value, c4d.DESCFLAGS_SET_0) # Check if the node contains subgraphs for port in node.GetInputs() + node.GetOutputs(): subgraph = port.GetNodeGraph() if subgraph: traverse_nodes(subgraph, ext_value, int_value) def main(): # Get user values ext_str = gui.InputDialog("External Thickness", "1.0") int_str = gui.InputDialog("Internal Thickness", "1.0") try: ext_value = float(ext_str) int_value = float(int_str) except ValueError: gui.MessageDialog("Invalid number input.") return # Loop through all materials for mat in doc.GetMaterials(): if not mat.CheckType(1036224): # Redshift material continue node_material = mat.GetNodeMaterialReference() if not node_material: continue # Try all available graphs inside the material graphs = node_material.GetGraphs() if not graphs: continue print(f"Scanning material: {mat.GetName()}") for graph in graphs: traverse_nodes(graph, ext_value, int_value) c4d.EventAdd() if __name__ == "__main__": main()
-
Hey @annoyedUser,
Thank you for reaching out to us. Your code looks very much like generated by a chatbot or generated with the help of a chatbot. Please note our Support Procedures: Scope of Support regrading the usage of AI. Please also post into the correct forum for future topics, I have moved your topic into the Cinema 4D SDK forum.
Your code does not make too much sense, I cannot dissect all the issues there. It is possible to do with the Nodes API what you want to do but it is more an API for experts. You can find here some code examples for it. Novice users should rather use graph descriptions which is a less powerful but also simpler API.
Cheers,
FerdinandTo change the external thickness of each Contour node in a document, you could write something like using a graph description query:
"""Sets the external thickness of all 'Contour' nodes in Redshift material graphs of the active document to 2. """ 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`. def main() -> None: """Called by Cinema 4D when the script is being executed. """ # Iterate over the material graphs of all Redshift materials in the document. for graph in maxon.GraphDescription.GetMaterialGraphs( doc, maxon.NodeSpaceIdentifiers.RedshiftMaterial): # Apply a graph description to each of them which ... maxon.GraphDescription.ApplyDescription(graph, { # ... queries all nodes of type 'Contour' in the graph ... "$query": { "$qmode": maxon.GraphDescription.QUERY_FLAGS.MATCH_ALL | maxon.GraphDescription.QUERY_FLAGS.MATCH_MAYBE, "$type": "Contour", }, # ... so that we can set the thickness value of all matching nodes to 2. "External/Thickness": 2 }) if __name__ == '__main__': main()
-
F ferdinand moved this topic from General Talk
-
okay the docs you gave were great for insight
working code to change parameter of roughness for x given mat selections
import c4d import maxon from maxon import GraphDescription doc = c4d.documents.GetActiveDocument() # Get selected materials directly selected_materials = doc.GetActiveMaterials() # Modify roughness for each selected material for material in selected_materials: graph = GraphDescription.GetGraph(material, nodeSpaceId=maxon.NodeSpaceIdentifiers.RedshiftMaterial) GraphDescription.ApplyDescription(graph, { "$query": { "$type": "Standard Material" }, "Reflection/Roughness": 1 }) c4d.EventAdd()