Import Materials in PyMechanical

Rajesh Meena
Moderator, Employee Posts: 42

Comments
-
I am trying to automate a series of steady state thermal simulations with a same geometry and different heat flux boundary conditions imported from a CSV file. I have created a PyMechanical script attached to this email. The issue is that I couldn't find a way to import the material .xml file that is exported from WorkBench Engineering Data.
Is there an API for importing Materials in standalone mechanical?0 -
The Python API for importing Material is exposed from 232 onwards. For 231 version, you will have to use jscript.
You need to make sure that the xml file is not exported from future versions.For 232:
materials = DataModel.Project.Model.Materials
materials.Import(material_file) For 231:
material_file = material_file.replace("\", "\\")
script = 'DS.Tree.Projects.Item(1).LoadEngrDataLibraryFromFile("' + material_file + '");'
ExtAPI.Application.ScriptByName("jscript").ExecuteCommand(script)0