<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to find and delete a node in a NodeGraph?]]></title><description><![CDATA[<p dir="auto">I have a redshift material node graph. I would like to delete the default Material (com.redshift3d.redshift4c4d.nodes.core.material) within that graph. I can't figure out how to find this node or how to delete it once I find it.</p>
<pre><code>BaseMaterial* pMat = BaseMaterial::Alloc(Mmaterial);

NodeMaterial* pNodeMat = static_cast&lt;NodeMaterial*&gt;(pMat);

pNodeMat-&gt;AddGraph(RedshiftNodeSpaceIds::nodespace) iferr_return;

const maxon::nodes::NodesGraphModelRef&amp; nodeGraph = pNodeMat-&gt;GetGraph(nodeSpaceID) iferr_return;

const maxon::GraphNode rootNode = nodeGraph.GetRoot();

maxon::NodePath materialNodePath;
pNodeMat-&gt;GetMaterialNodePath(nodeSpaceID, materialNodePath) iferr_return;
materialNode = nodeGraph.GetNode(materialNodePath);

</code></pre>
<p dir="auto">materialNode now contains a node with the id "com.redshift3d.redshift4c4d.nodes.core.material". I only know this because I can see it in the NodeGraph editor in C4D. How do I find this node and how can I delete it?</p>
<p dir="auto">Thanks!<br />
Kent</p>
]]></description><link>http://developers.maxon.net/forum/topic/15035/how-to-find-and-delete-a-node-in-a-nodegraph</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Jul 2026 15:32:48 GMT</lastBuildDate><atom:link href="http://developers.maxon.net/forum/topic/15035.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 18 Sep 2023 03:38:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to find and delete a node in a NodeGraph? on Tue, 19 Sep 2023 01:50:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/ferdinand">@<bdi>ferdinand</bdi></a> said in <a href="https://developers.maxon.net/forum/post/72461" target="_blank" rel="noopener noreferrer nofollow ugc">How to find and delete a node in a NodeGraph?</a>:</p>
<blockquote>
<p dir="auto">Fig. I: The two IDs are displayed in the node editor info panel for the selected node. Make sure to have Preferences\Node Editor\Ids enabled to also see the node ID in addition to the asset ID.</p>
</blockquote>
<p dir="auto">I didn't know about this! I have been copying and pasting the selected nodes into a text editor up until now, which in itself is a very cool feature.</p>
]]></description><link>http://developers.maxon.net/forum/post/72475</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/72475</guid><dc:creator><![CDATA[kbar]]></dc:creator><pubDate>Tue, 19 Sep 2023 01:50:20 GMT</pubDate></item><item><title><![CDATA[Reply to How to find and delete a node in a NodeGraph? on Tue, 19 Sep 2023 01:45:46 GMT]]></title><description><![CDATA[<p dir="auto">Thanks <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/ferdinand">@<bdi>ferdinand</bdi></a> and <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/dunhou">@<bdi>Dunhou</bdi></a>! Using FindNodesByAssetId has done the trick.</p>
<p dir="auto">Unfortunately I can't jump to using the latest frameworks for everything just yet, but I will make sure to use the new methods for anything in 2024 onwards.</p>
]]></description><link>http://developers.maxon.net/forum/post/72474</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/72474</guid><dc:creator><![CDATA[kbar]]></dc:creator><pubDate>Tue, 19 Sep 2023 01:45:46 GMT</pubDate></item><item><title><![CDATA[Reply to How to find and delete a node in a NodeGraph? on Mon, 18 Sep 2023 09:01:32 GMT]]></title><description><![CDATA[<p dir="auto">Hey <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/kbar">@<bdi>kbar</bdi></a>,</p>
<p dir="auto">Thank you for reaching out to us and thank you <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/dunhou">@<bdi>Dunhou</bdi></a> for providing an answer in Python.</p>
<blockquote>
<p dir="auto">All C++ entity links in my answer intentionally point to the 2023.1 C++ documentation.</p>
</blockquote>
<h4>NodeMaterial Methods for Creating Graphs</h4>
<p dir="auto">The easiest way to do what you probably want to do, creating an empty graph, is using the method <a href="https://developers.maxon.net/docs/cpp/2023_1/class_node_material.html#ad4a6071fd4cfb52e9b6829f085d56491" target="_blank" rel="noopener noreferrer nofollow ugc">NodeMaterial::CreateEmptyGraph</a>. I would not recommend using <a href="https://developers.maxon.net/docs/cpp/2023_1/class_node_material.html#a8f9931f1e87634e1c00038773c07102d" target="_blank" rel="noopener noreferrer nofollow ugc">::AddGraph</a>, as this method has been deprecated; this already applies to 2023.¹ When you want to create the default graph, you now should use <a href="https://developers.maxon.net/docs/cpp/2023_1/class_node_material.html#a50d877f12e7523168fb5abfa735bfcbd" target="_blank" rel="noopener noreferrer nofollow ugc">::CreateDefaultGraph</a> instead.</p>
<p dir="auto">You can also compare the <a href="https://developers.maxon.net/docs/cpp/2023_1/page_manual_redshift_rendrer.html#example_redshift_rendrer_create_material" target="_blank" rel="noopener noreferrer nofollow ugc">2023.1 Create a Redshift Material</a> C++ example with its <a href="https://developers.maxon.net/docs/cpp/2023_2/page_manual_redshift_rendrer.html#example_redshift_rendrer_create_material" target="_blank" rel="noopener noreferrer nofollow ugc">2023.2 variant</a>, as the example itself makes the shift from <code>::AddGraph</code> to <code>::CreateEmptyGraph</code>.</p>
<h4>Predicting Node IDs in a Default Graph</h4>
<p dir="auto">When you create a non-empty Redshift graph, you must identify nodes in it via their asset ID. A node in a graph is identified by two things, its node ID which is unique to the instance, and the asset ID which is the same for all nodes of the same type.</p>
<p dir="auto"><img src="https://developers.maxon.net/forum/assets/uploads/files/1695026735549-3d4206a0-ecaa-4eca-8fd4-f880d943fa42-image.png" alt="3d4206a0-ecaa-4eca-8fd4-f880d943fa42-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"><em>Fig. I: The two IDs are displayed in the node editor info panel for the selected node. Make sure to have <code>Preferences\Node Editor\Ids</code> enabled to also see the node ID in addition to the asset ID.</em></p>
<p dir="auto">The <code>2023.1</code> example mentioned above makes use of asset IDs in this stretch of code to select the RS Material node contained in the (old) default graph:</p>
<pre><code class="language-cpp">// Find the RS-Material node which is contained within a standard Redshift material graph. This
    // example assumes that there is exactly one RS-Material node in the graph that is already 
    // connected to the output node (which is true for the RS default material as of S26).
    maxon::BaseArray&lt;maxon::GraphNode&gt; results;
    maxon::GraphModelHelper::FindNodesByAssetId(
      graph, rsmaterialId, false, results) iferr_return;
 
    if (results.GetCount() &lt; 1)
      return maxon::UnexpectedError(MAXON_SOURCE_LOCATION, "Could not find RS-Material node."_s);
 
    maxon::GraphNode rsmaterialNode = results[0];
</code></pre>
<p dir="auto">This also highlights the problem with it, as you are unable to distinguish two node instances of the same type in this manner. The default graph in the standard material system has predictable/persistent node IDs.</p>
<p dir="auto"><img src="https://developers.maxon.net/forum/assets/uploads/files/1695026312412-95e16d67-fd76-4f2e-aa25-5075d4064711-image.png" alt="95e16d67-fd76-4f2e-aa25-5075d4064711-image.png" class=" img-fluid img-markdown" /><br />
<em>Fig. II: The two nodes in the Standard Renderer default graph will always have the IDs <code>material</code>, and <code>bsdf</code>.</em></p>
<p dir="auto"><img src="https://developers.maxon.net/forum/assets/uploads/files/1695026435072-df209011-7ad7-4010-ba00-17061a3018a7-image.png" alt="df209011-7ad7-4010-ba00-17061a3018a7-image.png" class=" img-fluid img-markdown" /><br />
<em>Fig. III: The two nodes in the Redshift Renderer default material on the other hand will not have predictable IDs, as they are newly hashed for each graph.</em></p>
<p dir="auto">This forces you then to search the graph over asset IDs just as shown in the <code>2023.1</code> example.</p>
<h4>Resources</h4>
<ul>
<li><a href="https://github.com/PluginCafe/cinema4d_py_sdk_extended/tree/master/scripts/05_modules/node" target="_blank" rel="noopener noreferrer nofollow ugc">2024 Python Node Examples</a>: I just added three scripts which cover the very basics in Python. Their code is fully transferable to 2023.X C++.</li>
<li><a href="https://developers.maxon.net/docs/cpp/2023_1/page_manual_redshift_rendrer.html#example_redshift_rendrer_create_material" target="_blank" rel="noopener noreferrer nofollow ugc">2023.1 Create a Redshift Material</a>: Highlights the '<code>::AdGraph</code> or <code>::CreateDefaultGraph</code> and then sorting out what is what'-worflow discussed above.</li>
<li><a href="https://developers.maxon.net/docs/cpp/2023_1/page_manual_redshift_rendrer.html#example_redshift_rendrer_create_material" target="_blank" rel="noopener noreferrer nofollow ugc">2023.2 Create a Redshift Material</a>: Highlights the '<code>::CreateEmptyGraph</code>-workflow of starting with a blank canvas. Especially in the context of Redshift I would recommend using this.</li>
</ul>
<p dir="auto">Cheers,<br />
Ferdinand</p>
<p dir="auto">[1] I am aware that our documentation does not mention the deprecation on entities. In this case, the deprecation still has been covered by our old and manual change notes. The new automated changes notes do not cover this anymore. The underlying problem is here that Doxygen does parse C++ attributes, i.e., this:</p>
<p dir="auto"><img src="https://developers.maxon.net/forum/assets/uploads/files/1695025174006-8fc51e0c-3acd-4bcb-9c9f-5d0ab5042b54-image.png" alt="8fc51e0c-3acd-4bcb-9c9f-5d0ab5042b54-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Is not automatically converted into a <code>@deprecated</code>. I would have to mess with the Doxygen parsing to fix this, or pre-parse the frameworks to inject <code>@deprecated</code> markup. I consider both things too costly as we will move away from Doxygen rather sooner than later anyway.</p>
]]></description><link>http://developers.maxon.net/forum/post/72461</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/72461</guid><dc:creator><![CDATA[ferdinand]]></dc:creator><pubDate>Mon, 18 Sep 2023 09:01:32 GMT</pubDate></item><item><title><![CDATA[Reply to How to find and delete a node in a NodeGraph? on Mon, 18 Sep 2023 05:50:57 GMT]]></title><description><![CDATA[<p dir="auto">Hi@kbar,  I didn't know C++, but I think the method should be the same as python. I have two options for this task:</p>
<ul>
<li>
<p dir="auto">all maxon sdk stuffs, I modified the github example <a href="https://github.com/PluginCafe/cinema4d_py_sdk_extended/blob/master/scripts/05_modules/node/access_nodematerial_2024.py" target="_blank" rel="noopener noreferrer nofollow ugc">here</a></p>
</li>
<li>
<p dir="auto">use my <a href="https://developers.maxon.net/forum/topic/14842/a-free-custom-api-helper-for-octane-redshift-arnold" target="_blank" rel="noopener noreferrer nofollow ugc">renderEngine</a> library (custom wrapper for node gragh us maxon sdk)<br />
Hoping this helps.</p>
</li>
</ul>
<p dir="auto">Cheers~<br />
DunHou</p>
<hr />
<h3>maxon sdk</h3>
<pre><code class="language-python">import c4d
import maxon

doc: c4d.documents.BaseDocument # The active document.

def main():

    # For each #material in the currently active document get its #nodeMaterial reference.
    material: c4d.BaseMaterial
    for material in doc.GetMaterials():
        nodeMaterial: c4d.NodeMaterial = material.GetNodeMaterialReference()
    
        # To test if a material has a graph for a specific space, we must use the method #HasSpace. 
        # To support 3rd party render engines, you must ask them for their node space ID.
        for nid in ("net.maxon.nodespace.standard",                 # Standard Renderer
                    "com.redshift3d.redshift4c4d.class.nodespace"): # Redshift Renderer
            if not nodeMaterial.HasSpace(nid):
                continue
            
            # This material has a graph for the space #nid, we retrieve it.
            graph: maxon.GraphModelInterface = nodeMaterial.GetGraph(nid)
            if graph.IsNullValue():
                raise RuntimeError("Found malformed empty graph associated with node space.")
            
            result: list[maxon.GraphNode] = []
            asset_id = "com.redshift3d.redshift4c4d.nodes.core.material"
            maxon.GraphModelHelper.FindNodesByAssetId(graph, asset_id, True, result)
            
            # start remove
            with graph.BeginTransaction() as transaction:
                for i in result:
                    i.Remove()
                transaction.Commit()
            
    c4d.EventAdd()

if __name__ == "__main__":
    main()
</code></pre>
<h3>renderEngine</h3>
<pre><code class="language-python">import c4d,maxon
from renderEngine.redshift import redshift_helper as rs
doc: c4d.documents.BaseDocument # The active document.

def ModifyMaterial(material: rs.MaterialHelper):
    if material is None:
        return
    # transfer it to a instance of rs.MaterialHelper                
    if isinstance(material, c4d.BaseMaterial):
        material = rs.MaterialHelper(material)
        # modification has to be done within a transaction
        with rs.RSMaterialTransaction(material) as transaction:

            # return a list of material with giving node id
            RsMat = material.helper.GetNodes("com.redshift3d.redshift4c4d.nodes.core.material")
            for mat in RsMat:
                # remove it
                material.helper.RemoveShader(mat)
                       
if __name__ == "__main__":
    ModifyMaterial(doc.GetActiveMaterial())
</code></pre>
]]></description><link>http://developers.maxon.net/forum/post/72460</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/72460</guid><dc:creator><![CDATA[Dunhou]]></dc:creator><pubDate>Mon, 18 Sep 2023 05:50:57 GMT</pubDate></item></channel></rss>