String values for the "FindChild"?
-
Hi,
In the
modify_port_value_r24.py
script there is a section ofcolordePort = bsdfNodeInputs.FindChild("color")
The "color" is hardcoded where do I find the list of it in a given node?
P.S. I initially thought selecting the node and iterating the through the inputs and outputs would help me do so but the result can't be used.
fresnel@RmXcknhCJFllQ0WfACUcAo<com.redshift3d.redshift4c4d.nodes.core.fresnel.fresnel_useior fresnel@RmXcknhCJFllQ0WfACUcAo<com.redshift3d.redshift4c4d.nodes.core.fresnel.user_curve fresnel@RmXcknhCJFllQ0WfACUcAo<com.redshift3d.redshift4c4d.nodes.core.fresnel.facing_color fresnel@RmXcknhCJFllQ0WfACUcAo<com.redshift3d.redshift4c4d.nodes.core.fresnel.perp_color fresnel@RmXcknhCJFllQ0WfACUcAo<com.redshift3d.redshift4c4d.nodes.core.fresnel.ior
The "perp_color" or "facing_color" doesn't work (i.e.
FindChild("perp_color")
)
I tried using thenode.GetValue("effectivename")
doesn't work. Gives an error. -
Hi,
we included in the c++ documentation information about how to find those IDs. The show IDs command was moved to the preferences (Node editor) and replaced by a checkbox. From there, you will be able to find the symbol corresponding to the Id of the port. For Redshift, those symbols are not exposed so you need to use the value of the ID.
You also have the resource editor to understand how the descriptions is built. Launch the resource editor using the commander. If you click the first arrow on the top left, you can start typing the ID of the node, like "fresnel". The list size will shrink to only display the database where there is an element with "fresnel" on its name.
Once the node is selected, you will be able to select the port on the tree and see the
Identifier
field on the right in the General tab.
Redshift uses a full reverse domain name notation to identify its ports, so the Id of the port iscom.redshift3d.redshift4c4d.nodes.core.fresnel.fresnel_useior
Some port can be port bundle, you can see it from its datatype. Below you can see the redshift texture node. To define the value of the filename you need to know the bundle port's ID
The ports ID is
com.redshift3d.redshift4c4d.nodes.core.texturesampler.tex0
. As it is a port bundle, you need to check the subid. Search forcom.redshift3d.redshift4c4d.portbundle.file
in the database.
You will find that the port has the ID
path
.
hope that helped.Cheers,
Manuel -
Thanks for the response. And yes, your answer does present the ID of the Path (or the ID of the Port?) which I guess the one needed for the
connect
method (Well my recent threads is just really to have connect ports of two nodes together because I can't find a decent example)Anyhow, what I'm really after is the
String values for the "FindChild"?
The reason why I prefer it over the
com.redshift3d.redshift4c4d.nodes.core.fresnel.fresnel_useior
is because that one is so verbose.
I just want to useFindChild(fresnel_useior)
. Much clearer to read.Is this still possible? I tried checking the Resource Editor for some clues.
I triedFindChild(
perp_color)
FindChild(
Perpendicular Color`)Am I looking at the wrong areas?
-
There is no string they are just IDs. The string is converted to an maxon::Id
You can not use
fresnel_useior
because this is not the ID of the port. The ID of the port iscom.redshift3d.redshift4c4d.nodes.core.fresnel.fresnel_useior
(and yes this is a bit verbose)The symbol for this ID (at least in c++) should be redshift3d::redshift4c4d::nodes::core::fresnel::fresnel_useior but again they are not exposed.
@ferdinand created a nice c++ example about connecting ports in redshift and using the texture node. You can see there that he first search for the port bundle and then, search for the file port.
// Retrieve the "Filename" port of the texture node. maxon::GraphNode tex0InportRust = rustTextureNode.GetInputs().FindChild( maxon::Id("com.redshift3d.redshift4c4d.nodes.core.texturesampler.tex0")) iferr_return; if (!tex0InportRust.IsValid()) return maxon::UnexpectedError(MAXON_SOURCE_LOCATION, "Failed to access port."_s); // The "Filename" port is a port bundle which consists out of two sub-ports, the "path" and the // "layer" port. The texture URL is written into the "path" sub-port. maxon::GraphNode pathInportRust = tex0InportRust.FindChild(maxon::Id("path")) iferr_return; if (!pathInportRust.IsValid()) return maxon::UnexpectedError(MAXON_SOURCE_LOCATION, "Failed to access port."_s); // Set the path of the rust texture node to the URL of the rust texture asset. pathInportRust.SetDefaultValue(rustTextureUrl) iferr_return;
Cheers,
Manuel -
RE: There is no string they are just IDs.
Ah. I guess I was misguided.
I was thinking theFindChild
spits out the verbose id.
For the sake of argument, why did themodify_port_value.py
script used a string value?
colordePort = bsdfNodeInputs.FindChild("color")
That's the basis of my confusion lolRE: nice c++ example
Missed this one out. Thanks! At least now I have a base example to check. -
@bentraje said in String values for the "FindChild"?:
For the sake of argument, why did the modify_port_value.py script used a string value?
When I wrote the nodes examples, the symbols were not necessarily available, and/or public. The node API is now more stable, i need to update some examples.
Cheers,
Manuel -
Thanks for the response but it still gives me error though.
I tried this one:
fresnel_port = node.FindChild(maxon.Id("com.redshift3d.redshift4c4d.nodes.core.fresnel.fresnel_useior"))
It gives me an error of
TypeError: unable to convert builtins.NativePyData to @net.maxon.datatype.internedid
or is there a different way to access the port?
-
I also tried the actual string id
fresnel_port = node.FindChild("com.redshift3d.redshift4c4d.nodes.core.fresnel.fresnel_useior")
it gives me null.All of the examples in the github does not access one port (it access all ports) except for the
modify_port_value_r24.py
so I'm not sure how to proceed. -
Example in this thread is using a generic string too instead of an ID so can't really refer directly
https://developers.maxon.net/forum/topic/14101/how-to-show-nodes-api-nodes-in-the-node-editor/4
-
Hi,
sorry, we must define which version you want to use. Depending on the version this can vary a lot. On some version, functions are in a different class, Strings are not converted to maxon::Id. Using python for the node API was a bit limited in r25.
Cheers,
Manuel -
gotcha sorry about that.
what are my options for R25? (i.e. how can I use the FindChild with the Maxon Id ? ) -
hi,
Something like this should works in R25. This will find the base_color ports of the redshift material. The Material must be a standard material and the standard node must be selected.
import c4d import maxon from c4d import gui from maxon.frameworks import nodes # Main function def main(): mat = doc.GetActiveMaterial() if mat is None: raise ValueError("can't retrieve the selected material") nodespaceId = c4d.GetActiveNodeSpaceId() nodemat = mat.GetNodeMaterialReference() graph = nodemat.GetGraph(nodespaceId) def PrintNode(node): colorNode = node.GetInputs().FindChild("com.redshift3d.redshift4c4d.nodes.core.standardmaterial.base_color") print (colorNode) return True graph.GetSelectedTrueNodes(PrintNode) # With newest version of cinema 4D, the function to retrieve the selected nodes was moved to another class so instead use the new one. #maxon.GraphModelHelper.GetSelectedNodes(graph, maxon.NODE_KIND.ALL_MASK, PrintNode) # Execute main() if __name__=='__main__': main()
Cheers,
Manuel -
Gotcha. Thanks for the clarification.
Sorry for the trouble.Works as expected. Will close this thread now.