Is there any way to trriger the GraphNode "Add Layer" button with Python?
-
As shown in the following screenshot.
It's Vray NodeMaterial in the picture,but I found the same structure in scene_root Node and the C4D NodeMaterial.
I had tried GraphNode.SetValue and GraphNode.SetDefaultValue.but I don't know how to set the "value" because it's a Array<Tuple<Id, DataDictionary>> Type.
I did write some codes and I know that they are wrong.But I dont know how to correct it.from typing import Optional import c4d import maxon doc: c4d.documents.BaseDocument # The active document op: Optional[c4d.BaseObject] # The active object, None if unselected def main() -> None: material = doc.GetActiveMaterial() nodeMaterial = material.GetNodeMaterialReference() graph: maxon.GraphModelInterface = nodeMaterial.GetGraph(c4d.GetActiveNodeSpaceId()) layered_list = [] maxon.GraphModelHelper.FindNodesById(graph,"com.chaos.vray_node.texlayeredmax.texture_layers",maxon.NODE_KIND.INPORT, maxon.PORT_DIR.INPUT, False, layered_list) layered_node = layered_list[0] with graph.BeginTransaction() as transaction: data_dict:maxon.DataDictionary = {} key = "net.maxon.node.attribute.insertindex" value = 1 data_dict[key] = value tuple_l = ["_0",data_dict] array = {tuple_l} layered_node.SetDefaultValue(array) transaction.Commit() print(tuple_l) if __name__ == '__main__': main()
thanks.
-
Hello @karen ,
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
Unfortunately, no, you cannot trigger this UI button. This is a frequent stumbling block when trying to interact with C4D existing UI elements.
Cheers,
Ilia -
Hi! @i_mazlov ,
Thanks for your reply,I will take a look at the Forum and Support Guidelines.
About the question
Is there any other way to 'add layer' to the node other than ‘’press‘’ the button? -
I found the AddPorts() Method,Sorry I missed it before.
from typing import Optional import c4d import maxon doc: c4d.documents.BaseDocument # The active document op: Optional[c4d.BaseObject] # The active object, None if unselected def main() -> None: material = doc.GetActiveMaterial() nodeMaterial = material.GetNodeMaterialReference() graph: maxon.GraphModelInterface = nodeMaterial.GetGraph(c4d.GetActiveNodeSpaceId()) with graph.BeginTransaction() as transaction: layered_node = graph.AddChild(maxon.Id(),"com.chaos.vray_node.texlayeredmax") layers = layered_node.GetInputs().FindChild("com.chaos.vray_node.texlayeredmax.texture_layers") #The Layers portbundle layers.AddPorts(2, 1) #Add layers transaction.Commit() #Layer in Layers portbundle layers_list = [] layers.GetChildren(layers_list,maxon.NODE_KIND.INPORT) #Textureports and BlendMode_ports in Layers portbundle layers_texport_list = [tport for port in layers_list if (tport := port.FindChild("com.chaos.vray.portbundle.texture_layer.texture"))] layers_mode_list = [mport for port in layers_list if (mport := port.FindChild("com.chaos.vray.portbundle.texture_layer.blend_mode"))] print(layered_node) print(layers) print(layers_list) print(layers_texport_list) print(layers_mode_list) if __name__ == '__main__': main()