Skip to content

Python API

Scripting interface for Sim4Life

127 Topics 375 Posts
  • Exporting data to excel (csv) or matlab (mat)

    6
    0 Votes
    6 Posts
    1k Views
    AntoninoMCA
    Dear Redi, you can export arbitrary data to Matlab (e.g. field array and grid coordinates) using the Scipy.io library. A generic use of it is the following: import scipy.io as sio dict={'field':fieldarray,'xgrid':xgrid,'ygrid':ygrid,'zgrid':zgrid} sio.savemat(filename,dict) where xgrid,ygrid,zgrid are the vectors containing the cartesian coordinates of the grid.
  • Is there an equivalent of "Remove Parametrization" from the Python API?

    Solved python modeling
    3
    0 Votes
    3 Posts
    528 Views
    SylvainS
    Brilliant, thanks!
  • Creating a wire from a line/arc

    Solved
    6
    1 Votes
    6 Posts
    752 Views
    PeterStijnmanP
    Okay good to know!
  • Python script for Hyperthermia optimizer

    2
    0 Votes
    2 Posts
    305 Views
    SylvainS
    This error typically means that one algorithm (the Hyperthemia Field Optimizer, in your case) does not have a complete Python interface. Sometimes it means that some properties are not available via Python, sometimes it means you cannot use the algorithm at all (I am not sure in which category the Hyperthermia Optimizer falls). Note that there is a newer version of Sim4Life available (v4.0.1), but I don't think any change has been made to the Hyperthermia Field Optimizer in that release.
  • Exporting in .mat file of Electric field

    Solved
    3
    0 Votes
    3 Posts
    655 Views
    R
    I found the mistake. There was one pixel shift in the lines that i was comparing. The rest was correct.
  • How to compute the length of a spline using the Python API

    spline python api
    2
    1 Votes
    2 Posts
    924 Views
    PeterStijnmanP
    Works perfectly, thanks! Edit, I think you could also get away with: import s4l_v1.model as model import XCoreModeling def get_spline_length(spline): wire = XCoreModeling.GetWires(spline)[0] return wire.GetLength()
  • Entities Translation Transformation

    4
    0 Votes
    4 Posts
    507 Views
    SylvainS
    The behavior you are describing is a related to a not-so-uncommon misunderstanding of the .Transform property. Model entities in Sim4Life have a Transform property (which you access by obj.Transform, for example). This property holds the transformation matrix between the initial object and its final position. This means that it holds the composition of all the transformations that have been applied to this object since its creation. So when you write something like obj.Transform = Rotation(axis, ori, ang), it does not just rotate the object - it replaces the transformation by a simple rotation, erasing all previous displacements. To apply a rotation, one should instead use obj.ApplyTransform(Rotation(axis, ori, ang)). The same is true for applying a translation: first define a Translation object (which is usually independent of the Transform property of the object itself), then apply the transformation. For example: from s4l_v1.model import Vec3, Translation, Transform import numpy t = Translation(Vec3(-20, -16, 10)) # for a translation r = Rotation(Vec3(0, 0, 1), numpy.pi / 4) # for a rotation of angle pi/4 around the z-axis case = model.CreateSolidBlock(Vec3(0, 0, 0), Vec3(40, 16, -140)) case.ApplyTransform( t ) case.ApplyTransform( r )
  • Python API changes from SEMCAD 14.8 to SEMCAD 17

    Unsolved python api grid simulation
    2
    1 Votes
    2 Posts
    853 Views
    SylvainS
    The gridding algorithms are quite different in V17 compared to V14.8, so many options simply do not have a one-to-one conversion. The best strategy is probably to learn how to use the gridder in the GUI of SEMCAD 17 (in particular the Manual Grid Settings) and then use the "To-Python" function to auto-generate the corresponding Python scripts. I don't know V14.8 well enough to answer your other questions from the top of my head and my current V14.8 installation is acting up, so I can't help with your other questions right now. I will as soon as I fix my setup!
  • Is the function "To Polyline" available from the API?

    python
    2
    0 Votes
    2 Posts
    382 Views
    brynB
    I had a look but also did not find it, so I added a function ConvertToPolyline which will become available in the next release (you can test it internally next week).
  • 0 Votes
    1 Posts
    488 Views
    No one has replied
  • Planar cut using Python

    python modeling
    3
    0 Votes
    3 Posts
    649 Views
    SylvainS
    You're welcome! Note, however, that functions that are not part of the s4l_v1 module are not checked for backward compatibility between Sim4Life versions and their signatures are in principle allowed to vary (although this is quite rare, in practice). It is recommended to always try to use functions under the s4l_v1 module when possible, since only these are "officially" part of the API. This said, if you need to bend an object in Sim4Life v4.x or lower, use XCoreModeling.PlanarCut :-)
  • This topic is deleted!

    1
    0 Votes
    1 Posts
    3 Views
    No one has replied
  • Creating a CSV file from an algorithm's output table

    python api table csv
    1
    1 Votes
    1 Posts
    601 Views
    No one has replied
  • 0 Votes
    1 Posts
    445 Views
    No one has replied
  • 0 Votes
    1 Posts
    661 Views
    No one has replied
  • 0 Votes
    1 Posts
    1k Views
    No one has replied
  • Example of mask filter in postpro?

    python mask filter sar
    3
    1 Votes
    3 Posts
    909 Views
    pcrespoP
    Thanks so much!
  • Example using the model.Extrude function

    python extrude
    1
    0 Votes
    1 Posts
    386 Views
    No one has replied
  • Creating coils via Python

    python coils
    1
    1 Votes
    1 Posts
    492 Views
    No one has replied
  • How can I interpolate the last snapshot of data in thermal simulation

    Solved
    6
    1 Votes
    6 Posts
    748 Views
    A
    @sylvain Never mind, I figured it out why. Thanks anyway