<?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[trigger script when viewport camera is moved]]></title><description><![CDATA[<p dir="auto">Hey!</p>
<p dir="auto">I am working on a python plugin that sends renders to a webserver. It works well right now through a  "render and send image" button in a dialog window the plugin creates.<br />
I would love to send images when the viewport camera is moved or something changes in the scene with a visual impact, with a little timeout.<br />
basically the same as the redshift IPR, it updates only when something relevant to the scene changes.</p>
<p dir="auto">ChatGPT helped me find <em>one way</em> to do this by listening to messages.</p>
<pre><code>class SceneChangeListener(c4d.plugins.MessageData):
    
    BASE_URL = "http://127.0.0.1:8000/inputs"  # Base part of the URL

    def __init__(self, plugin):
        self.last_render_time = 0
        self.plugin = plugin

    def CoreMessage(self, id, bc):
        # print(f"core message received: {id}")
        if id == c4d.EVMSG_CHANGE:
            print(f"my message received:{id}")
            current_time = time.time()
            if current_time - self.last_render_time &gt;= 0.6:  # 300ms delay
                print(f"CoreMessage render triggered:{id}")
                self.last_render_time = current_time
                self.plugin.render(url=self.BASE_URL)
                # Trigger your render function here

        return True
</code></pre>
<p dir="auto">this works but it gets triggered a lot for anything.</p>
<p dir="auto">Next step is filtering a bit by messages. Ideally only when something that changes the main view, or I listen to only the messages I want to respond to, such as material manager, timeline, camera moves.</p>
<p dir="auto">I played around with a few more messages I found here:<br />
<a href="https://developers.maxon.net/docs/py/2024_2_0/consts/MSG_C4DATOM_PLUGINS.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://developers.maxon.net/docs/py/2024_2_0/consts/MSG_C4DATOM_PLUGINS.html</a>. None of the few I tried were really that useful.</p>
<p dir="auto">I guess these dont exist?  Happy to try another approach.</p>
]]></description><link>http://developers.maxon.net/forum/topic/15324/trigger-script-when-viewport-camera-is-moved</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 16:58:30 GMT</lastBuildDate><atom:link href="http://developers.maxon.net/forum/topic/15324.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 09 Jan 2024 10:53:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to trigger script when viewport camera is moved on Sat, 27 Jan 2024 13:28:02 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/i_mazlov">@<bdi>i_mazlov</bdi></a> thanks so much!<br />
some super useful insights here. I think I will have eventually to move to C++</p>
]]></description><link>http://developers.maxon.net/forum/post/73622</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/73622</guid><dc:creator><![CDATA[thomas]]></dc:creator><pubDate>Sat, 27 Jan 2024 13:28:02 GMT</pubDate></item><item><title><![CDATA[Reply to trigger script when viewport camera is moved on Fri, 12 Jan 2024 14:37:26 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/thomas">@<bdi>thomas</bdi></a>,</p>
<p dir="auto">You can use <a href="https://developers.maxon.net/docs/py/2024_2_0/modules/c4d.plugins/BaseData/MessageData/index.html?highlight=c4d%20plugins%20messagedata#c4d.plugins.MessageData" target="_blank" rel="noopener noreferrer nofollow ugc">c4d.plugins.MessageData</a> for creating the timer that would handle the "little timeout" part for you.</p>
<p dir="auto">For the editor camera being changed you can access if through the BaseDraw as shown in <a href="https://developers.maxon.net/docs/py/2024_2_0/misc/cookbook.html?highlight=geteditorcamera#how-to-get-the-active-editor-object-camera" target="_blank" rel="noopener noreferrer nofollow ugc">How to get the active editor/object camera</a>.</p>
<p dir="auto">Generally speaking, I'd suggest using the <a href="https://developers.maxon.net/docs/cpp/2024_2_0/class_scene_hook_data.html" target="_blank" rel="noopener noreferrer nofollow ugc">SceneHookData</a> plugin type and register it using the <a href="https://developers.maxon.net/docs/cpp/2024_2_0/c4d__scenehookdata_8h.html#afa56977be2afec4c95f4aca15a3b8f46" target="_blank" rel="noopener noreferrer nofollow ugc">RegisterSceneHookPlugin</a> function. This would give you more flexibility in checking different aspects of the document to treat them as a trigger for you to send data to the server (e.g. you could use <a href="https://developers.maxon.net/docs/cpp/2024_2_0/group___e_x_e_c_u_t_i_o_n_p_r_i_o_r_i_t_y.html" target="_blank" rel="noopener noreferrer nofollow ugc">EXECUTIONPRIORITY</a> for plugging into directly where you need in the <a href="https://developers.maxon.net/docs/cpp/2023_2/page_manual_cinemathreads.html#page_manual_cinemathreads_execute" target="_blank" rel="noopener noreferrer nofollow ugc">Scene Execution Pipeline</a>, and the <a href="https://developers.maxon.net/docs/cpp/2024_2_0/group___e_x_e_c_u_t_i_o_n_f_l_a_g_s.html#ggab7f79561ea302128a159a5073f500f06a7878504ba8e5ed36174b009c22a16f32" target="_blank" rel="noopener noreferrer nofollow ugc">EXECUTIONFLAGS::CAMERAONLY</a> could be something particularly of your interest). The downside is that scene hooks aren't exposed to python, so you need to develop C++ plugin to use it.</p>
<p dir="auto">Cheers,<br />
Ilia</p>
]]></description><link>http://developers.maxon.net/forum/post/73529</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/73529</guid><dc:creator><![CDATA[i_mazlov]]></dc:creator><pubDate>Fri, 12 Jan 2024 14:37:26 GMT</pubDate></item></channel></rss>