Material Properties: Basic Example#

Download the ExampleModel.slmd for this example.

Code Snippet: Manipulation of Material Properties#
from Slide2Scripting.Slide2Modeler import Slide2Modeler
from Slide2Scripting.MaterialProperties.MaterialProperty import HatchStyle
from Slide2Scripting.Utilities.ColorPicker import ColorPicker
import os, inspect

current_dir = os.path.dirname(os.path.abspath(inspect.getfile(lambda: None)))
Slide2Modeler.startApplication(60074)

slide2_modeler = Slide2Modeler(60074)
model = slide2_modeler.openFile(rf"{current_dir}\example_models\ExampleModel.slmd")

material_property_list = model.getMaterialProperties()

material1 = material_property_list[0]
material2 = material_property_list[1] if len(material_property_list) > 1 else material_property_list[0]

material1.setName("Glacial Till")
material1.setColor(ColorPicker.Indigo)
material1.setHatch(HatchStyle.HatchStyleHorizontal)
material1.setUseHatch(True)
material1.setUseSaturatedUnitWeight(True)
material1.setUnitWeight(21.0)
material1.setSaturatedUnitWeight(22.0)

print(material1.getName())
print(ColorPicker.getColorName(material1.getColor()))
print(material1.getHatch())
print(material1.getUseHatch())
print(material1.getUseSaturatedUnitWeight())
print(material1.getUnitWeight())
print(material1.getSaturatedUnitWeight())

if material2 is not material1:
	material2.setName("Sandy Clay")
	material2.setColor(ColorPicker.Gold)
	material2.setHatch(HatchStyle.HatchStyleVertical)
	material2.setUseHatch(True)
	material2.setUseSaturatedUnitWeight(False)
	material2.setUnitWeight(19.5)

	print(material2.getName())
	print(ColorPicker.getColorName(material2.getColor()))
	print(material2.getHatch())
	print(material2.getUseHatch())
	print(material2.getUseSaturatedUnitWeight())
	print(material2.getUnitWeight())

model.save()
model.close()

slide2_modeler.closeApplication()

Output#

Glacial Till
Indigo
HatchStyle.HatchStyleHorizontal
True
True
21.0
22.0
Sandy Clay
Gold
HatchStyle.HatchStyleVertical
True
False
19.5