how to loading engineering Data source and selecting materials using scripting

Options
Collins
Collins Member Posts: 17
First Comment Name Dropper

How do I select materials that are not in my favourites?

I notice that even after putting materials in my favourite folder once I run a new instance of mechanical using Pymechanical it doesn't show up there.

I have found this code below from @Ayush Kumar

here : https://discuss.ansys.com/discussion/1557/how-to-add-materials-from-material-library-in-mechanical-with-act#latest

Unfortunately, when I try it, it just refreshes the material but does not add any new material

cmd = """
library1 = EngData.OpenLibrary(
Name="Composite Materials",
Source="Composite_Materials.xml")
system1 = GetSystem(Name="SYS")
engineeringData1 = system1.GetContainer(ComponentName="Engineering Data")
matl1 = engineeringData1.ImportMaterial(
Name="E-Glass",
Source="Composite_Materials.xml")
"""

ExtAPI.Application.ScriptByName('journaling').ExecuteCommand(cmd)
ExtAPI.DataModel.Project.Model.RefreshMaterials()

Comments

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 419
    5 Likes First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Options

    @Collins I tested today with 2024R1 and it seems work perfectly fine. Which version are you testing with?

  • Collins
    Collins Member Posts: 17
    First Comment Name Dropper
    edited June 25
    Options

    @Ayush Kumar

    Thank you
    2024R1too

    cmd = """
    library1 = EngData.OpenLibrary(
    Name="Composite Materials",
    Source="Composite_Materials.xml")
    system1 = GetSystem(Name="SYS")
    engineeringData1 = system1.GetContainer(ComponentName="Engineering Data")
    matl1 = engineeringData1.ImportMaterial(
    Name="E-Glass",
    Source="Composite_Materials.xml")
    """

    ExtAPI.Application.ScriptByName('journaling').ExecuteCommand(cmd)
    ExtAPI.DataModel.Project.Model.RefreshMaterials()

    I am running the code the way it is above no changes, Am I supposed to change the "SYS" in the
    line : system1 = GetSystem(Name="SYS") to my system name?

    Or am I suppose to change anything in this code, I presume I want E-Glass as a way of testing if the code works but I don't get anything in my material list after running the code.

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 419
    5 Likes First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Options

    @Collins, this code gets executed on the WB level so, you need to check which system you making changes to. If you have multiple analysis systems on the WB project then you need to make sure you are using the correct name.

  • Collins
    Collins Member Posts: 17
    First Comment Name Dropper
    Options

  • Collins
    Collins Member Posts: 17
    First Comment Name Dropper
    Options

    @Ayush Kumar

    works just fine now thank you so much.

    I had multiple simulations in the workbench.