@i_mazlov Thanks a lot for your time.
You answered my question brilliantly.
Posts made by danielsian
-
RE: Create Radio Button in User Data
-
RE: Create Radio Button in User Data
Awesome, thanks @i_mazlov
Very nice approach to create an User Data entry.How can I find this kind of information when it is not documented, as I suppose there are other UD options without a symbol defined?
-
Create Radio Button in User Data
Hi,
I'm creating User Data through Python and I'm able to create a dropdown list (combobox) with this:cycle = c4d.GetCustomDataTypeDefault(c4d.DTYPE_LONG) cycle[c4d.DESC_CUSTOMGUI] = c4d.CUSTOMGUI_CYCLE
But this is not what I want at all, but the old and classic radio button, as below.
I'd expect to find something like 'c4d.CUSTOMGUI_RADIOBUTTONS' in the documentation, but there is nothing even close to this.
Is it possible to be created in Python?
-
RE: Flip spline in RSScalarRamp / Invert Gradient in RSRamp not possible in Node Material?
Thanks @ferdinand, you answered my question brilliantly, as you always do.
Cheers -
RE: Adding nodes to existing material won't auto arrange the node editor
Hey guys, how is it going with this BUG?
Is it gonna be fixed soon?
Thanks -
Flip spline in RSScalarRamp / Invert Gradient in RSRamp not possible in Node Material?
Hi there,
In a ShaderGraph material I'm able to flip the spline in a Scalar Ramp node as well as invert the gradient in a Ramp node by using:Flip()
InvertKnots()
Do we have similar methods for the Maxon API?
Do I need to invert the knots and points one by one manually?
If so I'd appreciate any examples.Thanks a lot
-
RE: How to group nodes in a Scaffold using Python
Hey @m_adam ,
Thanks for your help. It works now.
However, I'm wondering how I would have known that I needed to set the scaffold ID to the node. The documentation doesn't seem to explicitly mention this step. I might be wrong, but for someone without strong knowledge of the API, I'd never thought that way. I would rather added the selected nodes to a group, as this is what a scaffol is. Does that make sense?
As a side note, after adding the nodes to the scaffold group, they appear messy, actually the nodes are nicely arranged inside the group, but the scaffold is overlapping other nodes. This is likely related to the bug we discussed here: https://developers.maxon.net/forum/post/73446. Am I right?
Cheers
-
How to group nodes in a Scaffold using Python
Hi, I've been searching for examples on how to add nodes to a scaffold group in Python, but there is nothing available and the documentation is not helping too much as well....
This is what I was trying to do, creating a material based on the example from github and adding a scaffold and then trying to move some nodes into it. But of course it is not working as this is just an attempt from a trial and error.
Any help would be appreciated.Thanks
import c4d import maxon doc: c4d.documents.BaseDocument def main(): urlTexRust: maxon.Url = maxon.Url(r"asset:///file_edb3eb584c0d905c") urlTexSketch: maxon.Url = maxon.Url(r"asset:///file_3b194acc5a745a2c") # The node asset IDs idTextureNode: maxon.Id = maxon.Id("com.redshift3d.redshift4c4d.nodes.core.texturesampler") idMixNode: maxon.Id = maxon.Id("com.redshift3d.redshift4c4d.nodes.core.rscolormix") idRsStandardMaterial: maxon.Id = maxon.Id("com.redshift3d.redshift4c4d.nodes.core.standardmaterial") # Instantiate a material, get its node material and the graph for the RS material space. material: c4d.BaseMaterial = c4d.BaseMaterial(c4d.Mmaterial) if not material: raise MemoryError(f"{material = }") nodeMaterial: c4d.NodeMaterial = material.GetNodeMaterialReference() graph: maxon.GraphModelRef = nodeMaterial.CreateDefaultGraph( maxon.Id("com.redshift3d.redshift4c4d.class.nodespace")) if graph.IsNullValue(): raise RuntimeError("Could not add RS graph to material.") # Get the Standard Material node result: list[maxon.GraphNode] = [] maxon.GraphModelHelper.FindNodesByAssetId(graph, idRsStandardMaterial, True, result) if len(result) < 1: raise RuntimeError("Could not find RS Standard node in material.") standardNode: maxon.GraphNode = result[0] with graph.BeginTransaction() as transaction: # Add two texture nodes and a blend node to the graph. rustTexNode: maxon.GraphNode = graph.AddChild(maxon.Id(), idTextureNode) sketchTexNode: maxon.GraphNode = graph.AddChild(maxon.Id(), idTextureNode) mixNode: maxon.GraphNode = graph.AddChild(maxon.Id(), idMixNode) mixAmount: maxon.GraphNode = mixNode.GetInputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.rscolormix.mixamount") mixAmount.SetDefaultValue(0.5) # Get the ports and set the values pathRustPort: maxon.GraphNode = rustTexNode.GetInputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.texturesampler.tex0").FindChild("path") pathSketchPort: maxon.GraphNode = sketchTexNode.GetInputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.texturesampler.tex0").FindChild("path") pathRustPort.SetDefaultValue(urlTexRust) pathSketchPort.SetDefaultValue(urlTexSketch) # Get the color output ports of the two texture nodes and the color blend node. rustTexColorOutPort: maxon.GraphNode = rustTexNode.GetOutputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.texturesampler.outcolor") sketchTexColorOutPort: maxon.GraphNode = sketchTexNode.GetOutputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.texturesampler.outcolor") mixColorOutPort: maxon.GraphNode = mixNode.GetOutputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.rscolormix.outcolor") # Get the ports mixInput1Port: maxon.GraphNode = mixNode.GetInputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.rscolormix.input1") mixInput2Port: maxon.GraphNode = mixNode.GetInputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.rscolormix.input2") stdBaseColorInPort: maxon.GraphNode = standardNode.GetInputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.standardmaterial.base_color") # Connect the nodes rustTexColorOutPort.Connect(mixInput1Port, modes=maxon.WIRE_MODE.NORMAL, reverse=False) sketchTexColorOutPort.Connect(mixInput2Port, modes=maxon.WIRE_MODE.NORMAL, reverse=False) mixColorOutPort.Connect(stdBaseColorInPort, modes=maxon.WIRE_MODE.NORMAL, reverse=False) transaction.Commit() # Find all the texture nodes tex_nodes = [] maxon.GraphModelHelper.FindNodesByAssetId(graph, idTextureNode, True, tex_nodes) ################################ # my attempt of grouping the texture nodes in a Scaffold # with graph.BeginTransaction() as transaction: scaffold = graph.AddChild(maxon.Id(), maxon.Id("net.maxon.node.scaffold")) graph.MoveToGroup(scaffold, maxon.Id("idOfMyGroup"), tex_nodes) transaction.Commit() # ################################ doc.InsertMaterial(material) doc.SetActiveMaterial(material) c4d.EventAdd() if __name__ == "__main__": main()
-
RE: Adding nodes to existing material won't auto arrange the node editor
Thanks @Dunhou, I appreciate your reply confirms what seems to be a bug, and I wonder if @m_adam could confirm it based on the working code I provided, which demonstrates the issue in a simple way.
-
Adding nodes to existing material won't auto arrange the node editor
Hi there, I'm adding nodes to an existing node material and I'm not being able to get a nice and organized result in the node editor, even after all connections are done.
However, if I create a material from scratch, then add the nodes and connect them the same way, the node editor finds an optimized way to organize the graph and the result is nice as expected.So, these are the 2 approaches and the result:
1- add and connect nodes within an existing material - the new nodes are overlapping each other
2- create the material and then add and connect the nodes within it - the new nodes are nicely organizedHow can I get a nice result with approach 1?
I used the example create_redshift_nodematerial_2024.py for the approach 2.
For the approach 1 I'm commenting the line:createRSMaterial()
import c4d import maxon doc: c4d.documents.BaseDocument # The active document. def createRSMaterial(): urlTexRust: maxon.Url = maxon.Url(r"asset:///file_edb3eb584c0d905c") urlTexSketch: maxon.Url = maxon.Url(r"asset:///file_3b194acc5a745a2c") # The node asset IDs idTextureNode: maxon.Id = maxon.Id("com.redshift3d.redshift4c4d.nodes.core.texturesampler") idMixNode: maxon.Id = maxon.Id("com.redshift3d.redshift4c4d.nodes.core.rscolormix") idRsStandardMaterial: maxon.Id = maxon.Id("com.redshift3d.redshift4c4d.nodes.core.standardmaterial") # Instantiate a material, get its node material and the graph for the RS material space. material: c4d.BaseMaterial = c4d.BaseMaterial(c4d.Mmaterial) if not material: raise MemoryError(f"{material = }") nodeMaterial: c4d.NodeMaterial = material.GetNodeMaterialReference() graph: maxon.GraphModelRef = nodeMaterial.CreateDefaultGraph( maxon.Id("com.redshift3d.redshift4c4d.class.nodespace")) if graph.IsNullValue(): raise RuntimeError("Could not add RS graph to material.") # Get the Standard Material node result: list[maxon.GraphNode] = [] maxon.GraphModelHelper.FindNodesByAssetId(graph, idRsStandardMaterial, True, result) if len(result) < 1: raise RuntimeError("Could not find RS Standard node in material.") standardNode: maxon.GraphNode = result[0] with graph.BeginTransaction() as transaction: # Add two texture nodes and a blend node to the graph. rustTexNode: maxon.GraphNode = graph.AddChild(maxon.Id(), idTextureNode) sketchTexNode: maxon.GraphNode = graph.AddChild(maxon.Id(), idTextureNode) mixNode: maxon.GraphNode = graph.AddChild(maxon.Id(), idMixNode) mixAmount: maxon.GraphNode = mixNode.GetInputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.rscolormix.mixamount") mixAmount.SetDefaultValue(0.5) # Get the ports and set the values pathRustPort: maxon.GraphNode = rustTexNode.GetInputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.texturesampler.tex0").FindChild("path") pathSketchPort: maxon.GraphNode = sketchTexNode.GetInputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.texturesampler.tex0").FindChild("path") pathRustPort.SetDefaultValue(urlTexRust) pathSketchPort.SetDefaultValue(urlTexSketch) # Get the color output ports of the two texture nodes and the color blend node. rustTexColorOutPort: maxon.GraphNode = rustTexNode.GetOutputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.texturesampler.outcolor") sketchTexColorOutPort: maxon.GraphNode = sketchTexNode.GetOutputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.texturesampler.outcolor") mixColorOutPort: maxon.GraphNode = mixNode.GetOutputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.rscolormix.outcolor") # Get the ports mixInput1Port: maxon.GraphNode = mixNode.GetInputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.rscolormix.input1") mixInput2Port: maxon.GraphNode = mixNode.GetInputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.rscolormix.input2") stdBaseColorInPort: maxon.GraphNode = standardNode.GetInputs().FindChild( "com.redshift3d.redshift4c4d.nodes.core.standardmaterial.base_color") # Connect the nodes rustTexColorOutPort.Connect(mixInput1Port, modes=maxon.WIRE_MODE.NORMAL, reverse=False) sketchTexColorOutPort.Connect(mixInput2Port, modes=maxon.WIRE_MODE.NORMAL, reverse=False) mixColorOutPort.Connect(stdBaseColorInPort, modes=maxon.WIRE_MODE.NORMAL, reverse=False) transaction.Commit() doc.InsertMaterial(material) doc.SetActiveMaterial(material) c4d.EventAdd() def main(): # create a RS material createRSMaterial() # Get the material material = doc.GetActiveMaterial() # Check if the material exists and is a node material if not material or not material.IsInstanceOf(c4d.Mmaterial): return # Get the node material nodeMaterial = material.GetNodeMaterialReference() nodespaceId = c4d.GetActiveNodeSpaceId() rsNodeSpaceId = maxon.Id("com.redshift3d.redshift4c4d.class.nodespace") if nodespaceId != rsNodeSpaceId: return # Get the graph try: graph = nodeMaterial.GetGraph(nodespaceId) except: return # Set the asset IDs idTextureNode = maxon.Id("com.redshift3d.redshift4c4d.nodes.core.texturesampler") idColorCorrection = maxon.Id("com.redshift3d.redshift4c4d.nodes.core.rscolorcorrection") # Find all the texture nodes tex_nodes = [] maxon.GraphModelHelper.FindNodesByAssetId(graph, idTextureNode, True, tex_nodes) if not tex_nodes: return for node in tex_nodes: for out_port in node.GetOutputs().GetChildren(): for dest_port, wires in out_port.GetConnections(maxon.PORT_DIR.OUTPUT, None, maxon.Wires.All(), maxon.WIRE_MODE.ALL): with graph.BeginTransaction() as transaction: # Remove existing connection maxon.GraphModelHelper.RemoveConnection(out_port, dest_port) # Create node colorCorrectionNode = graph.AddChild(maxon.Id(), idColorCorrection) # Get the ports cc_inPort = colorCorrectionNode.GetInputs().FindChild("com.redshift3d.redshift4c4d.nodes.core.rscolorcorrection.input") cc_outPort = colorCorrectionNode.GetOutputs().FindChild("com.redshift3d.redshift4c4d.nodes.core.rscolorcorrection.outcolor") # Connect the nodes cc_outPort.Connect(dest_port, modes=maxon.WIRE_MODE.NORMAL, reverse=False) out_port.Connect(cc_inPort, modes=maxon.WIRE_MODE.NORMAL, reverse=False) transaction.Commit() doc.InsertMaterial(material) c4d.EventAdd() if __name__ == "__main__": main()
-
RE: Add normal button in a dialog that opens a dialog to select a folder
Thanks again for clarifying my question, @ferdinand
By reading your reply and watching the example you provided, I think a TreeView could be a good way to try.Instead of printing a list of filenames in a multiline edit text, it could instead feed a TreeView with the given folder being the parent and all files with subfolders as children, and so I could select the ones I need in order to perform another operation with those selected filenames.
Let me know please if this is something possible.
Cheers -
RE: Add normal button in a dialog that opens a dialog to select a folder
Thank you, @ferdinand, as always, very kind and helpful. You nailed it.
From your last example, when the button "Run" is pressed, the multiline edit text prints a list with the files from the given directory, and that is read-only.
Is there any way to have the same thing but with the ability to select some of the printed filenames from the list rather than only read them?I know this is probably another question not directly related to the main query, but I'm just taking advantage of the fact that you provided a very nice example that happens to be another problem I'm trying to solve.
I wonder if I could achieve what I've just described by using an InExcludeData list, with the files listed there? If so, could you suggest another example?
-
Add normal button in a dialog that opens a dialog to select a folder
I need a button to open a dialog so the user can select a folder, and the button returns the path.
I know I can usec4d.CUSTOMGUI_FILENAME
but I don't want an edit text box, but just the button. A normal button.
I can add a button with thisself.AddButton(1000, c4d.BFH_SCALEFIT, initw=200, inith=20, name='Select Folder')
but I don't know how to select a directory on click.
According to the documentation, I can use the pluginid CUSTOMGUI_BUTTONAnd that is what I was trying, but it doesn't work:
bc = c4d.BaseContainer() bc[c4d.FILENAME_DIRECTORY] = True self.AddCustomGui(1000, c4d.CUSTOMGUI_BUTTON, name="Select Folder", flags=c4d.BFH_SCALEFIT, minw=200, minh=200, customdata=bc)
Is it possible to add a normal button on a gui dialog so that I can pick a folder from there?
-
RE: Gradient Interpolation Error in 2024 release
@m_adam
Brilliant!
Thanks a lot! -
Gradient Interpolation Error in 2024 release
With the new version 2024 I'm no longer able to set the interpolation knots in a gradient this way:
knot[c4d.GRADIENTKNOT_INTERPOLATION] = c4d.GRADIENT_INTERPOLATION_SMOOTHKNOT
as the console returns
AttributeError: module 'c4d' has no attribute 'GRADIENT_INTERPOLATION_SMOOTHKNOT'
But this way it works:
knot[c4d.GRADIENTKNOT_INTERPOLATION] = 2
However, from the new documentation, it should work as it always has been:
https://developers.maxon.net/docs/py/2024_0_0/modules/c4d/CustomDataType/Gradient/index.html#Gradient.SetDataAm I missing anything?
BTW I'm experimenting with this example provided in the Extended Python SDK:
""" Copyright: MAXON Computer GmbH Author: Maxime Adam, Ferdinand Hoppe Description: - Showcases the usage of the custom data type `c4d.Gradient`. - Creates a material with a gradient shader in the color channel. Class/method highlighted: - c4d.BaseMaterial - c4d.BaseShader - c4d.Gradient - c4d.BaseContainer """ import c4d def main(): # Create a new material and a new gradient shader. material = c4d.BaseMaterial(c4d.Mmaterial) shader = c4d.BaseShader(c4d.Xgradient) # Get a copy of the c4d.Gradient data referenced by the gradient shader # and a copy of the knot data stored in the c4d.Gradient data. The knot # data is expressed as a c4d.BaseCoontainer. gradient = shader[c4d.SLA_GRADIENT_GRADIENT] knotData = gradient.GetData(c4d.GRADIENT_KNOT) # Iterate over all knots in the knot data container and set their # interpolations to linear. Each knot in the knot data container is itself # a c4d.BaseContainer, storing the data for a single knot. for _, knot in knotData: knot[c4d.GRADIENTKNOT_INTERPOLATION] = c4d.GRADIENT_INTERPOLATION_NONE # Items can also be retrieved by their index from a BaseContainer, here # the first index, i.e., second item, in the container. In this case the # position of the knot is written and then the knot container is being # written back into the index its has been retrieved from. knot = knotData.GetIndexData(1) knot[c4d.GRADIENTKNOT_POSITION] = 0.5 knotData.SetIndexData(1, knot) # After these modifications the knots must be written back into the # c4d.Gradient data, because GetData() returned a copy above. This also # does apply to the shader and its gradient for the same reason. gradient.SetData(c4d.GRADIENT_KNOT, knotData) shader[c4d.SLA_GRADIENT_GRADIENT] = gradient # Aside from assigning the shader to the correct parameter of the # material, it is also important to call BaseList2D.InsertShader(), as # otherwise the setup will not work. material.InsertShader(shader) material[c4d.MATERIAL_COLOR_SHADER] = shader # Finally, the material is being inserted into the active document and an # update event is being pushed event to Cinema 4D, so that its GUI can # catch up to our changes. 'doc' is a predefined module attribute in # script manger scripts which points to the active document. It is # equivalent to c4d.documents.GetActiveDocument(). doc.InsertMaterial(material) c4d.EventAdd() if __name__=='__main__': main()
-
RE: Python Xpresso node detect Userdata button press message
@ferdinand Thanks for your comprehensive explanation. I really appreciate that.
Cheers -
RE: Python Xpresso node detect Userdata button press message
@ferdinand Thanks for you quick response. I've read somewhere while researching about this issue, if I'm not wrong it was even you replying to another query regarding something similar to this, saying that it would be possible to get a core message in the Python Xpresso.
So based on that, is this a possible workaround? -
Python Xpresso node detect Userdata button press message
Hi there,
I have a Null with userdata and a button in it.
I also have an Xpresso tag and a Python Node that I want it to listen a message from that button. The button ID is 10.
In my research I wasn't able to find any examples for what I need, so I tried this code that I found.
I know this is for Python Generator obj, but I want something similar, and to learn how to detect a button from my userdata and then run an action.Thanks a lot
import c4d def message(mid, data): if mid is c4d.MSG_DESCRIPTION_COMMAND: if not isinstance(data, dict) or "id" not in data: raise RuntimeError("Malformed message data.") senderDescId = data["id"] if senderDescId[0].id == c4d.ID_USERDATA and senderDescId[1].id == 10: print ("User data button has been pressed.") # then run an action in main() function def main(): # waiting for the right message before running anything...
-
RE: Test "Lock Overrides" in Python
Thank you very much @ferdinand, that's exactly what I was looking for.
Cheers