Import Materials in PyMechanical

Options
Rajesh Meena
Rajesh Meena Moderator, Employee Posts: 67
First Anniversary Solution Developer Community of Practice Member Ansys Employee 5 Likes

Comments

  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 67
    First Anniversary Solution Developer Community of Practice Member Ansys Employee 5 Likes
    Options

    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?

  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 67
    First Anniversary Solution Developer Community of Practice Member Ansys Employee 5 Likes
    Options

    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)