Unsolved How to Change Material Properties with Python?

Hello,

I'm trying to change EMFDTD material properties in a simulation that's already set up, using the VIP Body Models.

If I change the conductivity value, it immediately resets itself to the original value - how do I get it to keep my new value?

aa4df71a-f9d4-4fae-b942-ec638d650dea-image.png

I'm getting "s" from this answer, to get the list of materials:
https://forum.zmt.swiss/topic/16/how-to-update-material-settings-using-the-material-database-from-python/2

Thank you!

Hey there,
I am not sure if this will fix your issue, but I can provide you with a piece of code that I used to apply material settings to the tissues in my simulations:

# dictionary containing all tissue names and entities in the simulation:
all_tissues_present = {}

if 'Bone_cortical' in all_entities: 
	print('Bone assigned')
	entity_bone1 = all_entities["Bone_cortical"]
	all_tissues_present["Bone_cortical"] = entity_bone1

# Dictionary containing material properties such as conductivity
tissue_conductivities = {
	'Scalp': [0.439, 1], 
	'Cerebrum_white_matter': [0.348, 10], 
	'Cerebrum_grey_matter': [0.419, 9], 
	'Cerebrospinal_fluid': [1.88, 8], 
	'Bone_cortical': [0.00645, 3],
         }

# Code to assign material settings to the correct tissues. Using the dictionaries above this can then be done in a for-loop:

for tissue_name, tissue_entity in all_tissues_present.items():
     material_settings = emlf.MaterialSettings()
     components = [tissue_entity] 
     material_settings.Name = tissue_name
     material_settings.ElectricProps.Conductivity = 
     tissue_conductivities[tissue_name][0], Unit("S/m")		
     simulation.Add(material_settings, components)

I hope this helps and wish you a very nice day.

Best

Thank you very much, this is really helpful!

How do you access the initial "all_entities" list?

I've tried

import s4l_v1.model as model

for e in model.AllEntities:
	print(e)

but I this error:

TypeError: 'type' object is not iterable

try for e in model.AllEntities():

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