Skip to content

Python API

Scripting interface for Sim4Life

127 Topics 375 Posts
  • Obtain material properties from material database

    3
    0 Votes
    3 Posts
    612 Views
    R

    Hi Haza,

    yes, i managed to get the corresponding material with :
    tissue_X_entity.MaterialName
    Each entity of the anatomical model has this attribute which is visible also through the GUI.
    thanks

  • This topic is deleted!

    1
    0 Votes
    1 Posts
    54 Views
    No one has replied
  • Clone As Static in API

    4
    0 Votes
    4 Posts
    376 Views
    SylvainS

    Hi Matthew, thanks for the additional information. If I understand correctly, there are mainly 3 steps at play here, each of which repeated a certain number of times:

    Posing the anatomical model to the desired posture Moving the model to the desired position inside the coil Running the simulation

    What I would do for a workflow like this is:

    a) Pose the model to the desired posture [in the GUI]
    b) "Clone As Static" the desired posture [in the GUI]
    c) Export the posed model to a .sab file [using a script in the GUI, but clicking buttons could also do] a) Starting from scratch, load the coil and load the posed model [using a script]
    b) Move the model to the desired position [using a script]
    c) Setup the simulation [using a script] Run the simulation [using a script]
    (4). Postprocess the simulation [using a script]

    So to answer your initial question: I still don't know how to Clone As Static from a script, but since I also don't know how to use the POSER from a script I would anyway still have to use the GUI to create each posture (and then the "Clone as static" is only one click away...).
    Let me know if I misunderstood your workflow, or if you find a better way to achieve it than what I suggested.

  • draw hemisphere

    3
    0 Votes
    3 Posts
    271 Views
    A

    thank you! It works 🙂
    I finally had to separate the two hemispheres because I wanted to impose a boundary condition on one sphere and a different boundary condition on the other, but if they were too close it didn't work.

    69ed604f-852c-43d3-b4df-4b4c43b5a472-image.png

  • "Scripter" troubles

    2
    0 Votes
    2 Posts
    284 Views
    S

    When starting and initializing Sim4Life, I do also get the error mentioned before in another thread "Error: too many positional options have been specified on the command line"

  • Plot Ellipsoid

    4
    0 Votes
    4 Posts
    456 Views
    A

    Thanks for the answer, it works!
    I hadn't seen the feature Stretch.

  • how to use python API

    1
    0 Votes
    1 Posts
    258 Views
    No one has replied
  • how to Create PolyLine using an array of points with 100 elements

    2
    0 Votes
    2 Posts
    309 Views
    E

    yes you can.
    Use the function CreatePolyLine from the module XCoreModeling
    This function takes a list of points as input. Points need to be Vec3 objects

    smth like:
    import XCoreModeling
    from s4l_v1.model import Vec3
    #points is your array of 100 points with spatial coordinates
    points = [Vec3(p) for p in points]
    XCoreModeling.CreatePolyline(points)

  • Python code does not work with S4L v.6.0

    2
    0 Votes
    2 Posts
    256 Views
    PeterStijnmanP

    It might be that they changed the sim4life python module between the two versions. You could check the functions you call from the sim4life module in the API browser. If that doesn't work, I would suggest posting the code (or a minimal working example) here so people can look more specifically.

  • This topic is deleted!

    1
    0 Votes
    1 Posts
    2 Views
    No one has replied
  • Forcing imported modules to refresh after updating

    2
    0 Votes
    2 Posts
    600 Views
    M

    This is common. Once you import a script, it becomes cached so even if you make changes to it and save it, python won't see the changes. You need to reload it as you said if you make changes to the imported script after running your main script.

  • Applying smoothing to a mesh with the API

    1
    0 Votes
    1 Posts
    179 Views
    No one has replied
  • 0 Votes
    2 Posts
    816 Views
    SylvainS

    This looks quite good, thank you for providing your scripts.
    Note that, for the second method, you could create your cylinder directly at the desired position:

    cylinder2 = model.CreateSolidCylinder(Vec3(0,1,-15),Vec3(0,1,-15),0.5)

    There is also the XCoredModeling.CoverWires() function that allows you to make a surface (i.e. face) out of a circle entity.

    Last, but not least, note that the line model_to_grid_filter.MaximumEdgeLength is ultimately what determines the tradeoff between accuracy and computational cost of the interpolation (since it defines the resolution of the triangulated mesh on which the interpolation is done).

  • Simulation results show as nan+nanj

    4
    0 Votes
    4 Posts
    601 Views
    L

    Oh that worked! Thank you 🙂

  • plot a specific parameter on a surface

    1
    1 Votes
    1 Posts
    201 Views
    No one has replied
  • 1 Votes
    3 Posts
    413 Views
    J

    Thank you for your prompt reply! That's helped a lot, I didn't know how to implement the 'magnetic_energy_evaluator.Outputs["Magnetic Energy"].Data' or the 'mag_data.GetComponent(0)[0]' lines.
    I realise now that I probably should have posted the code which I had attempted already. Thanks for helping me anyway!

  • Acoustic simulation - phase information needed (using Python)

    11
    1 Votes
    11 Posts
    1k Views
    M

    You need to make output_angle into an array and append the new values at the end every time (the i-th element will have the i-th phase you want)

    output_angle = numpy.array([]) for i in range(0,128): # your code output_angle = numpy.append(output_angle, numpy.angle(output))
  • This topic is deleted!

    1
    0 Votes
    1 Posts
    7 Views
    No one has replied
  • This topic is deleted!

    1
    0 Votes
    1 Posts
    5 Views
    No one has replied
  • Add a material to the Materials Database

    1
    0 Votes
    1 Posts
    260 Views
    No one has replied