how to set the path of a Textre node manually?
-
Lovely people,
Is this a wrong attempt to set the Path of a Texture node manually?
def create_material(self): doc = c4d.documents.GetActiveDocument() material = c4d.BaseMaterial(c4d.Mmaterial) if not material: raise MemoryError(f"{material = }") doc.InsertMaterial(material) # Get the node material for it and add a graph for the currently active material space to it. node_material = material.GetNodeMaterialReference() graph = node_material.CreateDefaultGraph(c4d.GetActiveNodeSpaceId()) if graph.IsNullValue(): raise RuntimeError("Could not add graph to material.") # Start a transaction to modify the graph with graph.BeginTransaction() as transaction: # Get texture files from the selected folder texture_files = self.print_allowed_files_in_folder(self.FOLDER_PATH) # Add texture nodes to the material graph for each texture file for texture_file in texture_files: texture_node = graph.AddChild(maxon.Id(), maxon.Id("com.redshift3d.redshift4c4d.nodes.core.texturesampler")) if texture_node is None: continue # Set the texture file path path_port = texture_node.GetInputs().FindChild("com.redshift3d.redshift4c4d.nodes.core.texturesampler.tex0").FindChild("path") path_port.SetDefaultValue(maxon.Url("file:///" + texture_file)) # Assuming local file path # Connect the texture node to the output node of the material output_port = graph.GetOutputPort(0) # Get output port of the material texture_color_port = texture_node.GetOutputs().FindChild("com.redshift3d.redshift4c4d.nodes.core.texturesampler.outcolor") texture_color_port.Connect(output_port, modes=maxon.WIRE_MODE.NORMAL, reverse=False) # Commit the transaction to apply the changes to the graph transaction.Commit()
-
Hey @momoko,
Thank you for reaching out to us. That depends what you mean by "is this a wrong attempt to set the Path of a Texture node manually?.
The lines
path_port = texture_node.GetInputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.texturesampler.tex0").FindChild("path") path_port.SetDefaultValue(maxon.Url("file:///" + texture_file)) # Assuming local file path
are the correct statements to address the path component of a Filename port bundle in a Texture node and then set its value. It depends here a bit what the author meant with "local" file, if he/she meant an URL in the file scheme/protocol, than this is the correct syntax. When
texture_file
is meant to be a relative path, you would have to use therelative:///
URL scheme.The code before these two lines is also okay, but the code after these two lines is pure gibberish.
- No offense, but your code somewhat strikes me as chat-bot (ChatGPT, CoPilot, etc.) generated. We do not support chat-bot output. They are helpful tools, but we cannot fix the gibberish they will come up with from time to time.
- We have multiple Nodes API Python examples and create_redshift_nodematerial_2024.py is very close to what you want to do here.
- When the Nodes API is too much for you, you could have a look at graph descriptions. They are more artist friendly, and loading a bunch of textures there should be pretty straight forward.
Cheers,
Ferdinand -
-
Hey @momoko,
please do not delete topics to which we have already answered. I am not sure if this is tied to you either having found a solution yourself, or that I pointed out that your code looks chat-bot-ish because it contains made-up function calls.
I have restored the topic, so that future readers can see our answer here.
Cheers,
Ferdinand -
-
@ferdinand I found a solution. Sorry
-
No need to be sorry