<?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[Python script to Python tag hand over?]]></title><description><![CDATA[<p dir="auto">I'm working on a script that creates a python tag with some code.</p>
<p dir="auto">Now I want the main script to talk to the python tag script and hand over some information.</p>
<p dir="auto">I do it in an incredibly hacky way, and like to know if this is appropriate, or if there is a more elegant/reliable way to do it?</p>
<pre><code>def add_python_tag(obj, crtl1, crtl2):
    if not obj:
        return

    pos_1 = get_global_position(crtl1)
    pos_2 = get_global_position(crtl2)

    distance_init = (pos_1 - pos_2).GetLength()

    python_tag = c4d.BaseTag(c4d.Tpython)

    python_code = """

import c4d

def main():

    #some more code ...

    pos_1 = get_global_position(ctrl_01)
    pos_2 = get_global_position(ctrl_02)

    distance_const = distance_init

    distance = (pos_1 - pos_2).GetLength()
    stretch_coefficient = distance_const / distance

    # and even more code ... 


# Execution
if __name__ == '__main__':
    main()

"""
    
    python_code = python_code.replace("distance_init", str(distance_init))

    python_tag[c4d.TPYTHON_CODE] = python_code
    obj.InsertTag(python_tag)

    c4d.EventAdd()
</code></pre>
]]></description><link>http://developers.maxon.net/forum/topic/15295/python-script-to-python-tag-hand-over</link><generator>RSS for Node</generator><lastBuildDate>Sun, 09 Aug 2026 14:41:55 GMT</lastBuildDate><atom:link href="http://developers.maxon.net/forum/topic/15295.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 19 Dec 2023 17:23:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Python script to Python tag hand over? on Thu, 21 Dec 2023 08:59:38 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for your help and nudging me into the right direction, I think I can work with that <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>
]]></description><link>http://developers.maxon.net/forum/post/73393</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/73393</guid><dc:creator><![CDATA[gaschka]]></dc:creator><pubDate>Thu, 21 Dec 2023 08:59:38 GMT</pubDate></item><item><title><![CDATA[Reply to Python script to Python tag hand over? on Wed, 20 Dec 2023 09:42:22 GMT]]></title><description><![CDATA[<p dir="auto">Hi your way of doing is correct if you want to share only constant information.</p>
<p dir="auto">However its a bit unpractical, I would recommend you to use <a href="https://realpython.com/python-f-strings/#interpolating-values-and-objects-in-f-strings" target="_blank" rel="noopener noreferrer nofollow ugc">f-string</a> instead of the replace, which is slow and can can have side effect since you can't pin-point a specific location in your code template.</p>
<p dir="auto">If you want something more dynamic, you will need to write data within the BaseContainer of the object (see <a href="https://developers.maxon.net/forum/topic/15294/python-tag-initalization/2" target="_blank" rel="noopener noreferrer nofollow ugc">Python tag initalization?</a>) In this example this is the tag that write to the BaseContainer, but nothing prevent you in your script from the script manager, to write in the BaseContainer of the tag and in the tag read the value.</p>
<p dir="auto">Cheers,<br />
Maxime.</p>
]]></description><link>http://developers.maxon.net/forum/post/73384</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/73384</guid><dc:creator><![CDATA[m_adam]]></dc:creator><pubDate>Wed, 20 Dec 2023 09:42:22 GMT</pubDate></item></channel></rss>