<?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[The code entered in the Python emitter has no effect.]]></title><description><![CDATA[<p dir="auto">Hello, in theory, the Python code linked to the Python effector should randomly move the object in the cloner by 100 cm along the Y axis — why isn't it working</p>
<pre><code>import c4d
import random

def main() -&gt; bool:
    md = c4d.modules.mograph.GeGetMoData(op)
    if md is None:
        return True

    count = md.GetCount()
    matrices = md.GetArray(c4d.MODATA_MATRIX)

    # Inizializza la lista dei frame solo una volta
    if not hasattr(op, "frames"):
        random.seed(42)
        op.frames = [random.randint(0, 75) for _ in range(count)]

    fps = doc.GetFps()
    current_frame = doc.GetTime().GetFrame(fps)

    for i in range(count):
        if current_frame &gt;= op.frames[i]:
            # Sposta il clone fuori scena (es. +100 cm su Y)
            m = matrices[i]
            m.off.y = 100
            matrices[i] = m
        else:
            # Mantieni la posizione originale (nessuna modifica)
            pass

    md.SetArray(c4d.MODATA_MATRIX, matrices, True)
    return True
</code></pre>
<p dir="auto"><a href="/forum/assets/uploads/files/1746175858290-15x10.c4d">15x10.c4d</a></p>
<p dir="auto">edit (<a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/ferdinand">@<bdi>ferdinand</bdi></a>): moved file link out of source code.</p>
]]></description><link>http://developers.maxon.net/forum/topic/16214/the-code-entered-in-the-python-emitter-has-no-effect</link><generator>RSS for Node</generator><lastBuildDate>Sun, 17 May 2026 20:52:03 GMT</lastBuildDate><atom:link href="http://developers.maxon.net/forum/topic/16214.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 02 May 2025 08:51:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to The code entered in the Python emitter has no effect. on Fri, 02 May 2025 12:19:06 GMT]]></title><description><![CDATA[<p dir="auto">Hey <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/fabio-b">@<bdi>Fabio-B</bdi></a>,</p>
<blockquote>
<p dir="auto"><img src="http://developers.maxon.net/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/26a0.png?v=0b8ddba251d" class="not-responsive emoji emoji-android emoji--warning" style="height:23px;width:auto;vertical-align:middle" title=":warning:" alt="⚠" /> Please note that we cannot provide support for AI generated code.  See <a href="https://developers.maxon.net/forum/topic/15244/support-procedures/3" target="_blank" rel="noopener noreferrer nofollow ugc">Support Procedures: Scope of Support</a> for details.</p>
</blockquote>
<p dir="auto">When you want the clones to move, or in other words to be animated over time, you will need a noise and cannot use hashes or random values, as they are not interpolated, i.e., continous.</p>
<pre><code class="language-py">"""Realizes an effector that attracts MoGraph particles spherically around its origin.

Add the example to a Matrix object to understand its effect. In Full Control mode we can realize
a true attraction force as we have full control over the particle values. Compare this example to
Parameter Control mode to understand the difference.
"""
import c4d
import mxutils

op: c4d.BaseObject # The Python Effector object containing this code.
gen: c4d.BaseObject # The MoGraph Generator executing `op`.
doc: c4d.documents.BaseDocument # The document `op` and `gen`are contained in.

def main() -&gt; bool:
    """Called by Cinema 4D to evaluate the effector.
    """
    # Get the particle data for the effector #op. Get out when either the data cannot be retrieved.
    data: c4d.modules.mograph.MoData = c4d.modules.mograph.GeGetMoData(op)
    if data is None:
        return 1.0

    # Get the matrices of the particles. This is the array we will modify.
    matrices: list[c4d.Matrix] = data.GetArray(c4d.MODATA_MATRIX)

    # For each particle write a new persistent random height value, hashed over the index of the 
    # particle. This will cause the height each time to be the same, as long as the index of the
    # particle does not change. One could also hash the position of the original particle to get a
    # height value that is not dependent on the index of the particle (e.g., when the user changes 
    # the order of the particles in the Matrix object).
    for i in range(data.GetCount()):
        pos: c4d.Vector = matrices[i].off
        y: float = c4d.utils.noise.Noise(matrices[i].off, doc.GetTime().Get()) * 25.0
        matrices[i].off = c4d.Vector(pos.x, y, pos.z)

        # Hash a height value over the position of the particle.
        # y: float = mxutils.g_random.HashVectorToNumber(matrices[i].off) * 25.0

    # Write the new data back.
    data.SetArray(c4d.MODATA_MATRIX, matrices, op[c4d.FIELDS].HasContent())
    return True
</code></pre>
<p dir="auto"><video class="embed-video-local" controls src="/forum/assets/uploads/files/1746188216235-recording-2025-05-02-141611.mp4">
<p dir="auto">Cheers,<br />
Ferdinand</p>
</video></p>]]></description><link>http://developers.maxon.net/forum/post/76393</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/76393</guid><dc:creator><![CDATA[ferdinand]]></dc:creator><pubDate>Fri, 02 May 2025 12:19:06 GMT</pubDate></item><item><title><![CDATA[Reply to The code entered in the Python emitter has no effect. on Fri, 02 May 2025 11:07:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/ferdinand">@<bdi>ferdinand</bdi></a> Thanks, Ferdinando. The code was written by the AI. Basically, I wanted a certain number of 2cm x 2cm planes to move randomly along the Y axis. My original grid contains 62,000 of them, but for convenience, the one I posted contains 150. Since my view is oriented in a certain way, as the clones move, they'll disappear from the scene, creating a sort of shimmering or swarming fade-out effect.</p>
]]></description><link>http://developers.maxon.net/forum/post/76392</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/76392</guid><dc:creator><![CDATA[Fabio B]]></dc:creator><pubDate>Fri, 02 May 2025 11:07:04 GMT</pubDate></item><item><title><![CDATA[Reply to The code entered in the Python emitter has no effect. on Fri, 02 May 2025 10:34:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/fabio-b">@<bdi>Fabio-B</bdi></a> Welcome to the Maxon developers forum and its community, it is great to have you with us!</p>
<h4>Getting Started</h4>
<p dir="auto">Before creating your next postings, we would recommend making yourself accustomed with our forum and support procedures. You did not do anything wrong, we point all new users to these rules.</p>
<ul>
<li><a href="/forum/topic/15242/">Forum Overview</a>: Provides a broad overview of the fundamental structure and rules of this forum, such as the purpose of the different sub-forums or the fact that we will ban users who engage in hate speech or harassment.</li>
<li><a href="/forum/topic/15244/">Support Procedures</a>: Provides a more in detail overview of how we provide technical support for APIs here. This topic will tell you how to ask good questions and limits of our technical support.</li>
<li><a href="/forum/topic/15243/">Forum Features</a>: Provides an overview of the technical features of this forum, such as Markdown markup or file uploads.</li>
</ul>
<p dir="auto">It is <strong>strongly</strong> recommended to read the first two topics carefully, especially the section <a href="/forum/topic/15244/support-procedures/4">Support Procedures: How to Ask Questions</a>.</p>
<h4>About your First Question</h4>
<p dir="auto">Your code contains a syntax error:</p>
<pre><code>op.frames = [random.randint(0, 75) for _ in range(count)]
</code></pre>
<p dir="auto"><code>op</code> is in this context a <code>BaseObject</code>, more precisely the effector for which this code is running. Since this type (<code>BaseObject</code>) has been implemented in C++, you cannot just put there an attribute named <code>frames</code> on it. That is simply not how it works. Did you write this code yourself or did you use an AI?</p>
<blockquote>
<p dir="auto">When I check the <code>DOCUMENT_INFO_FILEVERSION</code> of the document you submitted, I get there <code>'2025.2.1'</code>, i.e., the last public release, and not R25 (released in 2021). I will answer as if you are using Cinema 4D 2025. The code I show below will not run in R25.</p>
</blockquote>
<p dir="auto">To set the height of each particle to a fixed position, while using full control mode, you can basically use the barely modified default code.</p>
<pre><code>"""Realizes an effector that sets all particles to a y position of 25.
"""
import c4d

op: c4d.BaseObject # The Python Effector object containing this code.
gen: c4d.BaseObject # The MoGraph Generator executing `op`.
doc: c4d.documents.BaseDocument # The document `op` and `gen`are contained in.

def main() -&gt; bool:
    """Called by Cinema 4D to evaluate the effector.
    """
    # Get the particle data for the effector #op. Get out when either the data cannot be retrieved.
    data: c4d.modules.mograph.MoData = c4d.modules.mograph.GeGetMoData(op)
    if data is None:
        return 1.0

    # Get the matrices of the particles. This is the array we will modify.
    matrices: list[c4d.Matrix] = data.GetArray(c4d.MODATA_MATRIX)

    # For each particle write the new position to the matrix array.
    for i in range(data.GetCount()):
        old: c4d.Vector = matrices[i].off
        matrices[i].off = c4d.Vector(old.x, 25, old.z)

    # Write the new data back.
    data.SetArray(c4d.MODATA_MATRIX, matrices, op[c4d.FIELDS].HasContent())
    return True 
</code></pre>
<p dir="auto">When you want to give each particle a random height value, you could use <a href="https://developers.maxon.net/docs/py/2025_2_0/modules/maxon_generated/mxutils/mxutils.Random.html" target="_blank" rel="noopener noreferrer nofollow ugc">mxutils.Random</a> as it has been built for tasks exactly like this:</p>
<pre><code class="language-py">"""Realizes an effector that sets all particles to a y position of 25..
"""
import c4d
import mxutils

op: c4d.BaseObject # The Python Effector object containing this code.
gen: c4d.BaseObject # The MoGraph Generator executing `op`.
doc: c4d.documents.BaseDocument # The document `op` and `gen`are contained in.

def main() -&gt; bool:
    """Called by Cinema 4D to evaluate the effector.
    """
    # Get the particle data for the effector #op. Get out when either the data cannot be retrieved.
    data: c4d.modules.mograph.MoData = c4d.modules.mograph.GeGetMoData(op)
    if data is None:
        return 1.0

    # Get the matrices of the particles. This is the array we will modify.
    matrices: list[c4d.Matrix] = data.GetArray(c4d.MODATA_MATRIX)

    # For each particle write a new persistent random height value, hashed over the index of the 
    # particle. This will cause the height each time to be the same, as long as the index of the
    # particle does not change. One could also hash the position of the original particle to get a
    # height value that is not dependent on the index of the particle (e.g., when the user changes 
    # the order of the particles in the Matrix object).
    for i in range(data.GetCount()):
        old: c4d.Vector = matrices[i].off
        matrices[i].off = c4d.Vector(old.x, mxutils.g_random.HashNumberToNumber(i) * 25.0, old.z)

        # Hash a height value over the position of the particle.
        # y: float = mxutils.g_random.HashVectorToNumber(matrices[i].off) * 25.0

    # Write the new data back.
    data.SetArray(c4d.MODATA_MATRIX, matrices, op[c4d.FIELDS].HasContent())
    return True
</code></pre>
<p dir="auto">Result:<br />
<img src="/forum/assets/uploads/files/1746181990861-3528058b-e5ad-499e-8fe4-16ff6fff27c1-image-resized.png" alt="3528058b-e5ad-499e-8fe4-16ff6fff27c1-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Cheers,<br />
Ferdinand</p>
]]></description><link>http://developers.maxon.net/forum/post/76391</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/76391</guid><dc:creator><![CDATA[ferdinand]]></dc:creator><pubDate>Fri, 02 May 2025 10:34:28 GMT</pubDate></item></channel></rss>