Import Materials in PyMechanical
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 -
Thank you for the code above.
I have a question
Is this code designed to work only once, I am trying to import a new material after previously importing my first material and I always get an error,
Code executed:
For 232:materials = DataModel.Project.Model.Materials
materials.Import(material_file)Error: Error HRESULT E_FAIL has been returned from a call to a COM component.
what could be the problem
0 -
@Collins This was a bug in 232 standalone mechanical. It was possible to do material import only once.
0