Python API

Scripting interface for Sim4Life

113 Topics 314 Posts
  • Delete Simulation and Results

    13
    0 Votes
    13 Posts
    667 Views

    Hmm I am not sure I understand. Is it possible to share more of your code and explain exactly what is not working?

    I use the lines of code you posted regularly and it works just fine.

  • 0 Votes
    5 Posts
    361 Views

    Mesh_material = sim.AddMaterialSettings(themesh(fromstl))
    Mesh_material.Name = yourname
    Mesh_material.ElectricProps.Conductivity = v # S/m

  • 0 Votes
    2 Posts
    171 Views

    Nevermind, I found example code in the "tutorial_emlf_unstructured_neuron_electroceuticals.py" example file, see below:

    def CreateMesh(): """ Creates a Multidomain Mesh with predefined priorities between domains and specified global and local options """ sel=.05 # Suface Edge Length mel=.002 # Min Edge Length #create multi-domain mesh global_opt = xcm.GlobalUnstructuredMeshingOptions() global_opt.SurfaceEdgeLength = sel global_opt.MinEdgeLength = mel # Gets all the entities in the folder 'Nerve_Model' entities=s4l.model.AllEntities()['Nerve_Model'].Entities local_opt_dict={} for ent in entities: local_opt = xcm.LocalUnstructuredMeshingOptions() print((ent, ent.Name)) if 'Saline' in ent.Name : local_opt.Priority=0 elif 'Silicone' in ent.Name : local_opt.Priority=1 elif 'Electrode' in ent.Name : local_opt.Priority=2 elif 'Nerve' in ent.Name : local_opt.Priority=3 elif 'Interstitial' in ent.Name : local_opt.Priority=4 elif 'Connective' == ent.Name : local_opt.Priority=5 elif 'Connective_' in ent.Name : local_opt.Priority=5 elif 'Blood' in ent.Name : local_opt.Priority=6 elif 'Fascicle' in ent.Name : local_opt.Priority=7 local_opt_dict[ent]=local_opt print((local_opt.Priority)) # Creates an unstructured mesh on the domains using the defined options mesh = xcm.GenerateUnstructuredMesh(entities, global_opt, local_opt_dict) return

    I did have a followup, how do we optimize the surface edge length and minimum edge lengths?

  • cant assign entities

    3
    0 Votes
    3 Posts
    294 Views

    really thanks this is direction of solution
    what i did with friend

    Mesh2 = s4l.model.Import(r'C:\sintetic data\bones.stl')[0]
    so now Mesh2 is not tuple and has its own name bones meanwhile i write all in one script without functions so i dont need realy the entities as in the example of 2 plates supplied with sim4life ...
  • 0 Votes
    2 Posts
    151 Views

    Hi, unfortunately most algorithms (this one included) do not have the option to mute their info messages. So I don't think there is a way to suppress this kind of output in the console.
    As for the possible options for the Update() function, there is only one: overwrite=True/False, to determine the behavior of the exporter if the target file already exists. The Update() function is the equivalent of clicking the Refresh button in the algorithm in the GUI: it triggers the algorithm.
    If the API Browser is lacking, you can find more information (like the function signature) by typing e.g.

    help(excel_exporter.Update)

    in the Console.

  • Model To Python Script

    1
    0 Votes
    1 Posts
    160 Views
    No one has replied
  • S4L v6.0 python pip install tkinter

    9
    0 Votes
    9 Posts
    575 Views

    @jasper-goethals hei im new here, for sim4life Light v7.. still cant use Tkinter so use another module PyQt5 its not best solution but its work for me

  • Extract power balance

    3
    0 Votes
    3 Posts
    176 Views

    This works indeed! Thanks a lot!

  • This topic is deleted!

    1
    0 Votes
    1 Posts
    4 Views
    No one has replied
  • VSCode extension

    5
    1 Votes
    5 Posts
    517 Views

    I am not sure to be honest why that was an issue for me with that specific version only, I installed the new version and it was there so problem solved!

  • 0 Votes
    15 Posts
    755 Views

    @mkn how about you post your code. maybe somebody will show you where the bug is

  • Optimization to python

    3
    0 Votes
    3 Posts
    142 Views

    @Sylvain OK, thank you for the answer.

  • Export SAR to matlab for analysis

    6
    0 Votes
    6 Posts
    842 Views

    @sayimgokyar
    Note to myself:
    Press right-click on fields on output window and "refresh" button after setting up everything.

  • 0 Votes
    5 Posts
    242 Views

    Thanks @montanaro!

  • 0 Votes
    2 Posts
    128 Views
    No one has replied
  • This topic is deleted!

    1
    0 Votes
    1 Posts
    5 Views
    No one has replied
  • 0 Votes
    2 Posts
    195 Views

    Hello Aiping,

    Bellow is a small example which might help you.

    import s4l_v1 as s4l import XCoreModeling import random radius = 0.1 points = list() for ii in range(20): points.append(s4l.Vec3(random.randrange(0,20), random.randrange(0,20), random.randrange(0,20))) spline = XCoreModeling.CreateSpline(points) wire = XCoreModeling.ThickenWire(spline, radius)

    Regards,

    Spuky

  • Change EMLF boundary condition with Python

    2
    0 Votes
    2 Posts
    97 Views

    Easiest way is to right click on your simulation and click on 'To Python..'

    Run this to make sure it works. It should create a new simulation with the exact same parameters. You can then change whichever parameter you like and run it again

    Note: If I remember correctly, if you use 'To Python', a lot of the default settings won't show up in the code. if they don't show up (like the boundary condition),change them to some non-default value in your simulation before using 'To Python'.

  • How to suppress Voxelling info in console

    1
    0 Votes
    1 Posts
    82 Views
    No one has replied
  • 0 Votes
    3 Posts
    356 Views

    @sylvain Thank you for the advice Sylvain! I have tried doing as you suggested and using the StartNotebook.bat does start a Jupyter Server. Unfortunately, if I start a new Notebook and try to import a Sim4Life module, I again get a pop-up called FlexNet License Finder wanting the location of either the license or the license server.
    a490c780-3a1d-41ad-a116-8b2c43ada34b-image.png
    Just to be sure I have tried doing so on different computers to try and rule out a faulty installation, however the issue persists.
    I can confirm that there are no problems with using Sim4Life’s GUI or using the integrated scripter/console. I did take a closer look at the Sim4Life console though and noticed that upon start up the following message is displayed:
    8493be54-bcd1-4c7e-ad7d-5abb95b186e3-image.png
    So perhaps this is a license issue after all?