<?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[GetCache Does Not Work Inside the Python Generator]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I have a <code>Text</code> object inside the Python Generator. I want to "bake" down (or equivalent to current state object commant) the text object so I can access it further but the <code>GetCache</code> seems to return none.</p>
<pre><code class="language-python"># inside the python generator
def main() -&gt; c4d.BaseObject:
    text = c4d.BaseObject(1019268)
    text[c4d.PRIM_TEXT_TEXT] = "Generator"

    print (text.GetCache()) # returns None
    clone = text.GetClone()
    print (clone.GetCache()) # returns None

    # I also tried the `SendModellingCommand` but it gives me `False` instead of `True`
    base = c4d.utils.SendModelingCommand(c4d.MCOMMAND_CURRENTSTATETOOBJECT,[clone],c4d.MODELINGCOMMANDMODE_ALL,c4d.BaseContainer(),clone.GetDocument())

    print (clone) # returns False instead of True
</code></pre>
<p dir="auto">I'm guessting there is a prerequisite on the operation.<br />
What am I missing? <img src="http://developers.maxon.net/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/1f622.png?v=0b8ddba251d" class="not-responsive emoji emoji-android emoji--cry" style="height:23px;width:auto;vertical-align:middle" title=":cry:" alt="😢" /> <img src="http://developers.maxon.net/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/1f622.png?v=0b8ddba251d" class="not-responsive emoji emoji-android emoji--cry" style="height:23px;width:auto;vertical-align:middle" title=":cry:" alt="😢" /> <img src="http://developers.maxon.net/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/1f622.png?v=0b8ddba251d" class="not-responsive emoji emoji-android emoji--cry" style="height:23px;width:auto;vertical-align:middle" title=":cry:" alt="😢" /></p>
]]></description><link>http://developers.maxon.net/forum/topic/15508/getcache-does-not-work-inside-the-python-generator</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Jul 2026 04:11:51 GMT</lastBuildDate><atom:link href="http://developers.maxon.net/forum/topic/15508.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 03 May 2024 06:57:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to GetCache Does Not Work Inside the Python Generator on Fri, 03 May 2024 19:32:52 GMT]]></title><description><![CDATA[<p dir="auto">Hey <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/bentraje">@<bdi>bentraje</bdi></a>,</p>
<p dir="auto">I am glad that you found your solution, and yes, you are absolutely right, it should be  <code>GeGetCurrentThread </code>. I fixed that in my pseudo-code.</p>
<p dir="auto">Cheers,<br />
Ferdiand</p>
]]></description><link>http://developers.maxon.net/forum/post/74264</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/74264</guid><dc:creator><![CDATA[ferdinand]]></dc:creator><pubDate>Fri, 03 May 2024 19:32:52 GMT</pubDate></item><item><title><![CDATA[Reply to GetCache Does Not Work Inside the Python Generator on Fri, 03 May 2024 14:30:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/ferdinand">@<bdi>ferdinand</bdi></a></p>
<p dir="auto">Thanks for the response. Your code works without the program freezing up (although I think it's GeGetCurrentThread instead of GetCurrentThread()). Other than that, it works as expected.</p>
<p dir="auto">Ah. I didn't think to just pass objects from different documents.</p>
<p dir="auto">I was thinking of something like this:</p>
<ol>
<li>All in the same document. Create a dummy object in the same document. In this way, the cache is already created because it now exist.</li>
<li>Clone it. Store the data.</li>
<li>Delete the dummy object in the same document.</li>
</ol>
<p dir="auto">The problem was that in #3, the generator no longer has access to that object for some reason. So it keeps creating a dummy object lol</p>
<p dir="auto">Anyway, enough for my excuses. Sorry for the trouble and thanks again for your patience.</p>
]]></description><link>http://developers.maxon.net/forum/post/74261</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/74261</guid><dc:creator><![CDATA[bentraje]]></dc:creator><pubDate>Fri, 03 May 2024 14:30:39 GMT</pubDate></item><item><title><![CDATA[Reply to GetCache Does Not Work Inside the Python Generator on Fri, 03 May 2024 19:31:25 GMT]]></title><description><![CDATA[<p dir="auto">Hey <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/bentraje">@<bdi>bentraje</bdi></a>,</p>
<p dir="auto">you are bound by the <a href="https://developers.maxon.net/docs/py/2024_4_0a/manuals/manual_threading.html#threading-information" target="_blank" rel="noopener noreferrer nofollow ugc">threading restrictions</a> in the <code>main</code> function of a Python Generator object, you are despite its name off-main-thread there and cannot modify the active scene. Both example scripts expand on this and that you have to use dummy documents in these cases to execute SMC or built the caches of an object.</p>
<p dir="auto">Inserting your <code>text</code> into <code>doc</code> (a.k.a. the active document) will result in infinite recursion on top of that (your freeze). Because <code>doc</code> contains your Python Generator object <code>pygen</code>. When you now insert <code>text</code> into <code>doc</code> from <code>pygen.main()</code> (i.e., the cache building function of <code>pygen</code>), and then execute the passes on <code>doc</code>, it will try to build the cache for <code>pygen</code>. Which will then run <code>pygen.main()</code> again, which will insert <code>text</code> into <code>doc</code>, and then try to build the caches on <code>doc</code>, which will then ...</p>
<p dir="auto">You must allocate a dummy document in your <code>main</code> function. Then insert all the newly allocated objects you want to build the caches for into this dummy document and execute the passes on it. Then you can clone the caches of these objects to return the clones as the output of your generator.</p>
<p dir="auto">Again, both script files which I have posted highlight this exact workflow.</p>
<p dir="auto">I wrote this blindly as I am currently sitting in a train with no Cinema 4D or code editor:</p>
<pre><code class="language-py">import c4d
import mxutils

from mxutils import CheckType

def main():
    # Allocate the text object and a document. Use CheckType to make sure to fail gracefully when
    # allocation goes wrong. Insert #text into #temp. 
    text = CheckType(c4d.BaseObject(1019268))
    temp = CheckType(c4d.documents.BaseDocument())
    temp.InsertObject(text)
    
    # Execute the passes on temp.
    temp.ExecutePasses(c4d.threading.GeGetCurrentThread(), True, True, True, c4d.BUILDFLAGS_NONE) 
    
    # Clone the cache, making sure with CheckType that the cache exists and then that the
    # cloning did not fail.
    data: c4d.BaseObject = CheckType(CheckType(text.GetCache()).GetClone(c4d.COPYFLAGS_NONE))

    # text and temp are destroyed automatically after the function scope has been left.
    # Since Python's GC can be a bit derpy you can also call BaseDocument.Flush to streamline
    # things.
    temp.Flush()

    return data
</code></pre>
<p dir="auto">Cheers,<br />
Ferdinand</p>
]]></description><link>http://developers.maxon.net/forum/post/74260</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/74260</guid><dc:creator><![CDATA[ferdinand]]></dc:creator><pubDate>Fri, 03 May 2024 19:31:25 GMT</pubDate></item><item><title><![CDATA[Reply to GetCache Does Not Work Inside the Python Generator on Fri, 03 May 2024 13:29:40 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/ferdinand">@<bdi>ferdinand</bdi></a></p>
<p dir="auto">I admit I'm on the slow side. It's a bit hard to comprehend on my level.</p>
<p dir="auto">Can I get a baseline answer (yes or no) on:</p>
<pre><code class="language-python">The examples are for Python Script/Manager and not for Python Generator (which is what I am after).
Is it doable in Python Generator?
</code></pre>
<p dir="auto">I can execute your script just find. It gives me caches etc. But when it comes to generator it does not.<br />
For example, as soon as I add <code>BaseDocument.ExecutePasses</code> the document freezes</p>
<pre><code class="language-python">def PrintCacheTree():
   ...

def GetCaches():
   ...

def main():
    text = c4d.BaseObject(1019268)
    doc.InsertObject(text)
    doc.ExecutePasses(None, False, False, True, c4d.BUILDFLAGS_NONE) 
    GetCaches(text)
    return text
</code></pre>
]]></description><link>http://developers.maxon.net/forum/post/74259</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/74259</guid><dc:creator><![CDATA[bentraje]]></dc:creator><pubDate>Fri, 03 May 2024 13:29:40 GMT</pubDate></item><item><title><![CDATA[Reply to GetCache Does Not Work Inside the Python Generator on Fri, 03 May 2024 12:34:38 GMT]]></title><description><![CDATA[<p dir="auto">Hey <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/bentraje">@<bdi>bentraje</bdi></a>,</p>
<p dir="auto">I understand that one has not always the time to get into the details of things, and that this file might look a bit much, but you will have to read it in order to understand caches. You must build the cache of your <code>Text</code> object, the script unpacks this bit by bit.</p>
<p dir="auto">Concretely you will have to call <code>BaseDocument.ExecutePasses</code> for a document holding your object, but I cannot help you when you just blindly copy and paste the script without trying to understand what it does.</p>
<p dir="auto">Cheers,<br />
Ferdinand</p>
]]></description><link>http://developers.maxon.net/forum/post/74256</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/74256</guid><dc:creator><![CDATA[ferdinand]]></dc:creator><pubDate>Fri, 03 May 2024 12:34:38 GMT</pubDate></item><item><title><![CDATA[Reply to GetCache Does Not Work Inside the Python Generator on Fri, 03 May 2024 10:19:01 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/ferdinand">@<bdi>ferdinand</bdi></a></p>
<p dir="auto">I'm not sure I get it. The examples are for Python Script/Manager and not for Python Generator (which is what I am after).</p>
<p dir="auto">Anyhow, I'm guessing you are referring to <code>GetCaches(node: c4d.BaseObject)</code> from <code>geometry_caches_s26.py</code></p>
<p dir="auto">If so I did try it in the Python Generator (not in the Python Script):</p>
<pre><code class="language-python">def PrintCacheTree():
   ...

def GetCaches():
   ...

def main():
    text = c4d.BaseObject(1019268)
    GetCaches(text)
    return text
</code></pre>
<p dir="auto">The result still gives me none, of which I am unable to access the individual extrude parameters of each letters.</p>
<pre><code class="language-python">Retrieving Caches:

Text.GetCache() = None
Text.GetDeformCache() = None

Cache Tree of 'Text':

 Text(Text)

Building Caches:

Cache for newly allocated object: None
Cache after executing the cache pass: &lt;c4d.PolygonObject object called Cube/Polygon with ID 5100 at 2640357790656&gt;

</code></pre>
]]></description><link>http://developers.maxon.net/forum/post/74253</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/74253</guid><dc:creator><![CDATA[bentraje]]></dc:creator><pubDate>Fri, 03 May 2024 10:19:01 GMT</pubDate></item><item><title><![CDATA[Reply to GetCache Does Not Work Inside the Python Generator on Fri, 03 May 2024 09:49:01 GMT]]></title><description><![CDATA[<p dir="auto">Hey <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/bentraje">@<bdi>bentraje</bdi></a>,</p>
<p dir="auto">look at the examples I have posted, it is all exactly layed out there <img src="http://developers.maxon.net/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=0b8ddba251d" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:23px;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
<p dir="auto">Cheers,<br />
Ferdinand</p>
]]></description><link>http://developers.maxon.net/forum/post/74252</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/74252</guid><dc:creator><![CDATA[ferdinand]]></dc:creator><pubDate>Fri, 03 May 2024 09:49:01 GMT</pubDate></item><item><title><![CDATA[Reply to GetCache Does Not Work Inside the Python Generator on Fri, 03 May 2024 09:06:10 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/ferdinand">@<bdi>ferdinand</bdi></a></p>
<p dir="auto">Thanks for the respond.</p>
<p dir="auto"><strong>RE: Caches do not exist for freshly allocated objects</strong><br />
Ah gotcha. Thanks for the confirmation.<br />
Based on your reply, I can do it through a python script (i.e. insert the object temporarily and just destroy it or something like that).</p>
<p dir="auto">But how do I go about it on Python Generator object? Is it possible?<br />
Ultimately, what I want is to have a procedural text object that allows me to modify the extrude parameter of each letter. Currently, the extrude parameter of a default text object applies to all letters.</p>
]]></description><link>http://developers.maxon.net/forum/post/74251</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/74251</guid><dc:creator><![CDATA[bentraje]]></dc:creator><pubDate>Fri, 03 May 2024 09:06:10 GMT</pubDate></item><item><title><![CDATA[Reply to GetCache Does Not Work Inside the Python Generator on Fri, 03 May 2024 08:43:06 GMT]]></title><description><![CDATA[<p dir="auto">Hey <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/bentraje">@<bdi>bentraje</bdi></a>,</p>
<p dir="auto">Thank you for reaching out to us. There are two different mistakes in your code:</p>
<ol>
<li>Caches do not exist for freshly allocated objects. They must be built in a document, see <a href="https://github.com/PluginCafe/cinema4d_py_sdk_extended/blob/master/scripts/04_3d_concepts/modeling/geometry/geometry_caches_s26.py" target="_blank" rel="noopener noreferrer nofollow ugc">geometry_caches_s26.py</a> for an overview of the subject.</li>
<li>Objects must be part of a document to be the subject of a modeling operation. While you did technically the right thing here, called <code>GeListNode.GetDocument</code> instead of blindly passing a document <code>clone</code> might or might not be a member of, the fact remains that <code>clone</code> is not yet a member of a document. See <a href="https://github.com/PluginCafe/cinema4d_py_sdk_extended/blob/master/scripts/04_3d_concepts/modeling/modeling_commands/smc_extrude_s26.py" target="_blank" rel="noopener noreferrer nofollow ugc">smc_extrude_s26.py</a> for a principal overview of SMC operations.</li>
</ol>
<p dir="auto">Cheers,<br />
Ferdinand</p>
]]></description><link>http://developers.maxon.net/forum/post/74250</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/74250</guid><dc:creator><![CDATA[ferdinand]]></dc:creator><pubDate>Fri, 03 May 2024 08:43:06 GMT</pubDate></item></channel></rss>