<?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[Is it possible to use Python API without opening Sim4Life?]]></title><description><![CDATA[<p dir="auto">Hi all,</p>
<p dir="auto">As stated in the subject title, I would like to know if it is possible to run simulations without opening the Sim4Life GUI? I have the *.smash file saved, with all the entities and models required for the simulations. I have the Python scripts ready with all simulation parameters. My question is, can I run the python scripts in a different IDE, e.g. Visual Studio, importing all the required packages?</p>
<p dir="auto">Thanks,<br />
gbh</p>
]]></description><link>https://forum.zmt.swiss/topic/588/is-it-possible-to-use-python-api-without-opening-sim4life</link><generator>RSS for Node</generator><lastBuildDate>Wed, 11 Mar 2026 13:30:09 GMT</lastBuildDate><atom:link href="https://forum.zmt.swiss/topic/588.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 13 Feb 2024 18:31:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Is it possible to use Python API without opening Sim4Life? on Thu, 12 Dec 2024 08:33:40 GMT]]></title><description><![CDATA[<p dir="auto">You can open a smash file using</p>
<pre><code class="language-py">import s4l_v1 as s4l

s4l.document.Open(smash_file_path)
</code></pre>
<p dir="auto">You can save it using</p>
<pre><code class="language-py">s4l.document.Save(smash_file_path)
</code></pre>
<p dir="auto">You can find a simulation using (assuming you have unique simulation names</p>
<pre><code class="language-py">sim = [sim for sim in s4l.document.AllSimulations if sim.Name == "the name of your simulation"][0]
</code></pre>
<p dir="auto">If you want to load different models (from .sab file or .smash), but don't need to load e.g. simulations (in .smash file), you can import the file</p>
<pre><code>entities = s4l.model.Import(file_path)
</code></pre>
<p dir="auto">if you need to reset the document or model because you are accumulating too many entities and memory use is getting too high, you can use e.g.</p>
<pre><code class="language-py"># reset the model
sl4.model.Clear()

# or keep entities, but discard model history
import XCoreModeling as xcm
xcm.GetActiveModel().ClearHistory()

# or reset entire document (reset model, simulations, analysis)
s4l.document.New()
</code></pre>
]]></description><link>https://forum.zmt.swiss/post/2029</link><guid isPermaLink="true">https://forum.zmt.swiss/post/2029</guid><dc:creator><![CDATA[bryn]]></dc:creator><pubDate>Thu, 12 Dec 2024 08:33:40 GMT</pubDate></item><item><title><![CDATA[Reply to Is it possible to use Python API without opening Sim4Life? on Wed, 11 Dec 2024 23:09:29 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/bryn">@<bdi>bryn</bdi></a>,</p>
<p dir="auto">Thanks for your reply! I have two follow-up questions.</p>
<ol>
<li>How would I call/activate a model that has been created beforehand?</li>
<li>How do I call (or refer to) a specific sim contained in a *.smash file, without opening the GUI.</li>
</ol>
<p dir="auto">For context:<br />
(1). I have several models stored in different .sab files. The models are all similar, with the only difference being the phantom in use. I want to perform a 'sweep' through various phantoms, and for each phantom, another sweep through various values for electrical conductivity.<br />
(2). Provided that I already have multiple *.smash files, each containing multiple finished simulations. I now need to extract the results and perform some analysis (e.g. field interpolation), then export to csv file.</p>
<p dir="auto">Currently, I already have scripts to generate -&gt; voxel/run -&gt; analyze -&gt; export the simulation data. But since I am using 8 different phantoms, contained in 8 separate *.smash batch, each with about 150 simulations, the pipeline takes a while and need manual monitoring or save/load.</p>
<p dir="auto">Thanks,<br />
gbh</p>
]]></description><link>https://forum.zmt.swiss/post/2028</link><guid isPermaLink="true">https://forum.zmt.swiss/post/2028</guid><dc:creator><![CDATA[gbgbha]]></dc:creator><pubDate>Wed, 11 Dec 2024 23:09:29 GMT</pubDate></item><item><title><![CDATA[Reply to Is it possible to use Python API without opening Sim4Life? on Wed, 14 Feb 2024 09:05:48 GMT]]></title><description><![CDATA[<p dir="auto">short answer: you can run most of the Python API without opening the Sim4Life user interface.</p>
<p dir="auto">you have different options</p>
<ul>
<li>you can call <code>Sim4Life.exe --run your_script.py</code></li>
<li>you can write scripts and run them using the python.exe in the Sim4Life installation</li>
<li>you can <a href="https://docs.python.org/3/library/venv.html" rel="nofollow ugc">create a virtual environment</a> with the Sim4Life packages, e.g. <code>"C:\Program Files\Sim4Life_6.2.2.6592\Python\python.exe" -m venv .venv --system-site-packages</code> and then use the python from this venv to run your script</li>
</ul>
<p dir="auto">The first option opens Sim4Life, runs the script, and closes Sim4Life again. It probably is the easiest option to work robustly.</p>
<p dir="auto">The latter two options run without the UI and by default without an application. In most cases, you will need an application though (e.g. the Application initializes the active model, which is needed for modeling). For Python scripting without the UI you can create a console application. We do this e.g., to run Python tests without opening the UI (which is slower). To create a console application you can usually call:</p>
<pre><code class="language-py">import XCore
XCore.GetOrCreateConsoleApp()

# now you can do some stuff
import s4l_v1 as s4l
sphere = s4l.model.CreateSolidSphere(s4l.model.Vec3(0.0), 1.0)
</code></pre>
]]></description><link>https://forum.zmt.swiss/post/1778</link><guid isPermaLink="true">https://forum.zmt.swiss/post/1778</guid><dc:creator><![CDATA[bryn]]></dc:creator><pubDate>Wed, 14 Feb 2024 09:05:48 GMT</pubDate></item></channel></rss>