Accessing Redshift Material Parameters with User Data
-
Hello,
I'm a beginner with Python in C4D and I've been having an issue with a Python tag for a while now and could use some assistance.
I can successfully control material parameters using user data with the following code:import c4d def main(): obj = op.GetObject() mat = obj[c4d.ID_USERDATA,1] strength = obj[c4d.ID_USERDATA,2] if mat is None or not isinstance(strength, float): print("error") return mat[c4d.MATERIAL_COLOR_BRIGHTNESS] = strength mat.Message(c4d.MSG_UPDATE)
However, I'm struggling to control Redshift material parameters in the same way. For example, I need to control the [c4d.REDSHIFT_SHADER_MATERIAL_DIFFUSE_WEIGHT] parameter.
What changes do I need to make in order to get this working properly?
Any help would be appreciated, thank you!
-
-
-
Hello @Easan,
Welcome to the Plugin Café forum and the Cinema 4D development 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 Guidelines, as they line out details about the Maxon SDK Group support procedures. Of special importance are:
- Support Procedures: Scope of Support: Lines out the things we will do and what we will not do.
- Support Procedures: Confidential Data: Most questions should be accompanied by code but code cannot always be shared publicly. This section explains how to share code confidentially with Maxon.
- Forum Structure and Features: Lines out how the forum works.
- Structure of a Question: Lines out how to ask a good technical question. It is not mandatory to follow this exactly, but you should follow the idea of keeping things short and mentioning your primary question in a clear manner.
About your First Question
Please excuse the delayed answer to your posting.
Assuming you're working with the 'RS Shader Graph' materials (please try specifying complete information in you next postings), I'd suggest you having a look into awesome example from Ferdinand: https://developers.maxon.net/forum/topic/14753/script-that-converts-redshift-materials-back-to-c4d-standard-ones?_=1691157330869
You can find simplified adopted code to your case below, which you can use as a starting point for your further investigations.
Cheers,
Ilia
Code:import c4d, maxon, typing from c4d.modules.graphview import * doc: c4d.documents.BaseDocument # The active document RS_MATERIAL_NODE_TYPENAME: str = 'Material' ID_NODE_TYPENAME: int = 1001 # The location at which type names are stored in an operator container. def iterTree(tree: GvNode) -> typing.Iterator[GvNode]: """Yields all nodes in the given shader tree #tree. """ yield tree for child in tree.GetChildren(): for desc in iterTree(child): yield desc def main(): mat = doc.GetActiveMaterial() if mat is None or not mat.CheckType(c4d.Mrsgraph): raise ValueError("There is no selected Redshift Shader Graph") # We traverse branches of this shader graph for info in mat.GetBranchInfo(c4d.GETBRANCHINFO_ONLYWITHCHILDREN): if info.get("name", "").lower() != "node": continue head: c4d.GeListHead | None = info.get("head", None) if not isinstance(head, c4d.GeListHead): raise RuntimeError(f"Malformed RS graph without head: {info}") root: GvNode = head.GetFirst() for node in iterTree(root): # Get the data of container of #node which among other things contains its real type name. opData: c4d.BaseContainer = node.GetOperatorContainer() if opData[ID_NODE_TYPENAME] != RS_MATERIAL_NODE_TYPENAME: # filter out all non-material nodes continue print(f'Diffuse weight: {node[c4d.REDSHIFT_SHADER_MATERIAL_DIFFUSE_WEIGHT]}') # Pushes an update event to Cinema 4D c4d.EventAdd() if __name__ == "__main__": main()
-
@i_mazlov Thank you very much for your help!