Skip to content

Python API

Scripting interface for Sim4Life

127 Topics 375 Posts
  • How can I install a new python package within Sim4Life

    3
    0 Votes
    3 Posts
    532 Views
    pcrespoP
    @sylvain Yes! thx
  • How can I read matlab export as a multi-dimensional array?

    2
    1 Votes
    2 Posts
    507 Views
    SylvainS
    In Matlab, you can reshape the Snapshot0 quantity in the following way. For cell-centered data with 3 components (e.g. Electric field E(x,y,z)): E = reshape(Snapshot0, [length(Axis0)-1, length(Axis1)-1, length(Axis2)-1, 3) which you can then use as: E[i,j,k,c] where c is an index to the field component and i,j,k are indices to the discretization of space. For point data with 1 component (e.g. Vector potential V(x,y,z)): V = reshape(Snapshot0, [length(Axis0), length(Axis1), length(Axis2)) which you can then use as: V[i,j,k] where i,j,k are indices to the discretization of space.
  • 0 Votes
    2 Posts
    379 Views
    SylvainS
    The function you are looking for is LinkMaterialWithDatabase(). This is how you can add new material settings with properties taken from the database import s4l_v1.document as document import s4l_v1.model as model sim = document.AllSimulations[0] for ent in model.AllEntities(): mats = sim.AddMaterialSettings([ent]) mats.Name = ent.Name sim.LinkMaterialWithDatabase(mats, str(ent.MaterialName)) To modify the settings of an existing simulation and update their properties, you can do something like this: import s4l_v1.simulation as simulation material_settings = [s for s in sim.AllSettings if isinstance(s, simulation.fdtd.MaterialSettings)] for mats in material_settings: material_name = mats.Name sim.LinkMaterialWithDatabase(mats, material_name)
  • How to remove warnings from deprecated functions?

    python
    1
    0 Votes
    1 Posts
    274 Views
    No one has replied
  • how to set the weights of field combiner in python?

    Moved Solved
    4
    1 Votes
    4 Posts
    466 Views
    SylvainS
    sorry, I gave you some code for the Simulation Combiner, not the Field Combiner... This is how you can use the GetWeights and SetWeights functions for the field combiner: >>> field_combiner.GetWeights() ((1+0j), (1+0j)) >>> field_combiner.SetWeights( ( (2+0j), (-3+0j) ) )
  • How to clear the Console via Python?

    Moved python
    1
    1 Votes
    1 Posts
    236 Views
    No one has replied
  • How to create a Cone from Python?

    Moved python
    2
    0 Votes
    2 Posts
    412 Views
    SylvainS
    There is no python interface for the Solid Cone creation tool. However, you can achieve the same result by using the SkinWires() primitive as follows: import s4l_v1.model as model import XCoreModeling c1 = model.CreateCircle(model.Vec3(0,0,0), model.Vec3(0,0,1), 50) c2 = model.CreateCircle(model.Vec3(0,0,50), model.Vec3(0,0,1), 25) XCoreModeling.SkinWires([c1, c2])