Skip to content
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

ZMT zurich med tech

  1. Home
  2. Sim4Life
  3. Python API
  4. How to update material settings using the material database from Python?

How to update material settings using the material database from Python?

Scheduled Pinned Locked Moved Python API
python
2 Posts 1 Posters 396 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SylvainS Offline
    SylvainS Offline
    Sylvain
    ZMT
    wrote on last edited by
    #1

    I am looking for the equivalent of "Update All Materials" in the GUI

    1 Reply Last reply
    0
    • SylvainS Offline
      SylvainS Offline
      Sylvain
      ZMT
      wrote on last edited by
      #2

      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)
      1 Reply Last reply
      0
      • D dbsim4 referenced this topic on
      • D dbsim4 referenced this topic on
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Search