<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://kfdani-001-site10.gtempurl.com/index.php?action=history&amp;feed=atom&amp;title=OpenSite%2FGuides%2FPython_property_expressions</id>
	<title>OpenSite/Guides/Python property expressions - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://kfdani-001-site10.gtempurl.com/index.php?action=history&amp;feed=atom&amp;title=OpenSite%2FGuides%2FPython_property_expressions"/>
	<link rel="alternate" type="text/html" href="https://kfdani-001-site10.gtempurl.com/index.php?title=OpenSite/Guides/Python_property_expressions&amp;action=history"/>
	<updated>2026-10-30T02:05:37Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.2</generator>
	<entry>
		<id>https://kfdani-001-site10.gtempurl.com/index.php?title=OpenSite/Guides/Python_property_expressions&amp;diff=864&amp;oldid=prev</id>
		<title>BathAfrica: Add rewritten practical lesson with steps, code and expected results</title>
		<link rel="alternate" type="text/html" href="https://kfdani-001-site10.gtempurl.com/index.php?title=OpenSite/Guides/Python_property_expressions&amp;diff=864&amp;oldid=prev"/>
		<updated>2026-10-29T21:01:03Z</updated>

		<summary type="html">&lt;p&gt;Add rewritten practical lesson with steps, code and expected results&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__NOTOC__&lt;br /&gt;
{{OpenSite scope}}&lt;br /&gt;
{{OpenSite lesson&lt;br /&gt;
|id=opensite.help.python-property-expressions&lt;br /&gt;
|summary=Store and explicitly recalculate a Python expression on a document property.&lt;br /&gt;
|prerequisites=A GUI+Python build or the embedded headless interpreter. The rectangular-section fixture uses the development host. Only evaluate expression sources you trust.&lt;br /&gt;
|steps==== Distinguish the two languages ===&lt;br /&gt;
Native formulas and Python expressions are separate. Set &amp;lt;code&amp;gt;language=&amp;quot;python&amp;quot;&amp;lt;/code&amp;gt; for this lesson. See [[OpenSite/Concepts/Expressions]].&lt;br /&gt;
&lt;br /&gt;
=== Store the expression ===&lt;br /&gt;
The lesson computes a projected length: width × cos(30°). Python uses &amp;lt;code&amp;gt;math.radians&amp;lt;/code&amp;gt; to convert degrees before evaluating cosine.&lt;br /&gt;
&lt;br /&gt;
=== Enable consent ===&lt;br /&gt;
Use {{MenuCommand|Edit → Enable Python Expressions}} in the desktop, or &amp;lt;code&amp;gt;document.set_python_expressions_enabled&amp;lt;/code&amp;gt; in the script. Consent does not itself run the stored expression.&lt;br /&gt;
&lt;br /&gt;
=== Recalculate explicitly ===&lt;br /&gt;
Use {{MenuCommand|Edit → Recalculate Python Expressions}} or &amp;lt;code&amp;gt;recalculate_python_expressions(doc)&amp;lt;/code&amp;gt;. The operation shares the console/editor execution lane.&lt;br /&gt;
&lt;br /&gt;
=== Review stale and failed results ===&lt;br /&gt;
After changing an input, recalculate again. A retained number marked pending, stale or invalid is not a current result. Opening a file does not silently execute its Python source.&lt;br /&gt;
&lt;br /&gt;
|result=For a width of 2 m, the checked result is approximately 1.7320508076 m. The assertion uses a 1e-9 m tolerance.&lt;br /&gt;
|limitations=Python expressions are trusted code, not a sandbox. A busy or paused execution lane blocks another evaluation. Stop is cooperative and may wait for native code to return.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Complete example ==&lt;br /&gt;
{{Code|lang=python|code=&amp;lt;nowiki&amp;gt;import math&lt;br /&gt;
import opensite&lt;br /&gt;
&lt;br /&gt;
created = opensite.execute(&amp;quot;document.create_section&amp;quot;, {&lt;br /&gt;
    &amp;quot;label&amp;quot;: &amp;quot;ProjectionBeam&amp;quot;,&lt;br /&gt;
    &amp;quot;width&amp;quot;: opensite.QuantityArgument(opensite.Q(&amp;quot;2 m&amp;quot;), &amp;quot;m&amp;quot;),&lt;br /&gt;
    &amp;quot;height&amp;quot;: opensite.QuantityArgument(opensite.Q(&amp;quot;1 m&amp;quot;), &amp;quot;m&amp;quot;),&lt;br /&gt;
})&lt;br /&gt;
doc, object_id = created[&amp;quot;document&amp;quot;], created[&amp;quot;object&amp;quot;]&lt;br /&gt;
opensite.execute(&amp;quot;document.set_expression&amp;quot;, {&lt;br /&gt;
    &amp;quot;document&amp;quot;: doc, &amp;quot;object&amp;quot;: object_id, &amp;quot;property&amp;quot;: &amp;quot;height&amp;quot;,&lt;br /&gt;
    &amp;quot;expression&amp;quot;: &amp;#039;document.get_object(&amp;quot;ProjectionBeam&amp;quot;).width * math.cos(math.radians(30))&amp;#039;,&lt;br /&gt;
    &amp;quot;language&amp;quot;: &amp;quot;python&amp;quot;,&lt;br /&gt;
})&lt;br /&gt;
# Consent and evaluation are separate operations.&lt;br /&gt;
opensite.execute(&amp;quot;document.set_python_expressions_enabled&amp;quot;, {&lt;br /&gt;
    &amp;quot;document&amp;quot;: doc, &amp;quot;enabled&amp;quot;: True,&lt;br /&gt;
})&lt;br /&gt;
opensite.recalculate_python_expressions(doc)&lt;br /&gt;
height = doc.property(object_id, &amp;quot;height&amp;quot;).si_value&lt;br /&gt;
assert abs(height - 2.0 * math.cos(math.radians(30))) &amp;lt; 1e-9&lt;br /&gt;
print(&amp;quot;Projected value:&amp;quot;, height, &amp;quot;m&amp;quot;)&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;os-page-nav&amp;quot;&amp;gt;{{Docnav|OpenSite/Guides/Native property formulas|OpenSite/Guides/Dimensionless material expressions|OpenSite/Guides|All guides}}&amp;lt;/div&amp;gt;&lt;br /&gt;
[[Category:OpenSite documentation]]&lt;/div&gt;</summary>
		<author><name>BathAfrica</name></author>
	</entry>
</feed>