How to create a custom material in Ansys Workbench programmatically ? By using APIs/ACT

Options
surajsalvi
surajsalvi Member Posts: 5
First Comment
edited June 2023 in Structures

System Information

  • Application : Ansys Workbench
  • Version : 2022 R2

Problem Statement

To create a material manually user can add material name in below option

After entering name a blank material is created

From the left side pallet, user can add material properties manually, and material object will be created with some properties in it.

How this can be done programmatically or using using ACT/ APIs ?

Best Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 804
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    edited June 2023 Answer ✓
    Options

    Hi @surajsalvi , this is doable via scripting at the project schematic level. There are recording capabilities at the project schematic level which I encourage you to use when you are trying to find the appropriate commands to do something.

    Go to File /Scripting and select "Record Journal":

    Then take the actions manually, and finally go to the same place (File / Scripting) and select "Stop Recording". This will create a .wbjn file which can be opened in a text editor and gives you the commands related to whichever action you have just done.

    To insert an engineering data component system and add a new material, the commands would be:

    # encoding: utf-8
    # 2023 R1
    SetScriptVersion(Version="23.1.153")
    template1 = GetTemplate(TemplateName="EngData")
    system1 = template1.CreateSystem()
    engineeringData1 = system1.GetContainer(ComponentName="Engineering Data")
    matl1 = engineeringData1.CreateMaterial(Name="custom_mat")
    matlProp1 = matl1.CreateProperty(
        Name="Elasticity",
        Behavior="Isotropic",
        Qualifiers={"Definition": "", "Behavior": "Isotropic"})
    matlProp1.SetVariableProperty(
        VariableName="Young's Modulus",
        Property="Unit",
        Value="MPa")
    matlProp1.SetData(
        Index=-1,
        Variables=["Young's Modulus"],
        Values=[["200000 [MPa]"]])
    matlProp1.SetData(
        Variables=["Poisson's Ratio"],
        Values=[["0.3"]])
    
    
    


  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 804
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Answer ✓
    Options

    Hi @surajsalvi , this script is based on Python. You can replay it by going to File / Scripting / Run script file.

    You could add to that script some Python code to open an Excel file and read the data from it, and execute this in batch mode. Please refer to second proposal of this post: https://discuss.ansys.com/discussion/2197/how-can-i-run-a-mechanical-script-in-batch-mode

Answers

  • surajsalvi
    surajsalvi Member Posts: 5
    First Comment
    Options

    Hi Pernelle Marone-Hitz,


    Your answer is really helpful this what I am looking for, but I am not sure how to run this programmatically.

    How I can run these commands ? is it using MAPDL ? or any Python or Java code ?


    I want to trigger material creation from external program using supported programming language by Ansys

  • surajsalvi
    surajsalvi Member Posts: 5
    First Comment
    Options

    Hi Pernelle,

    Thanks for your support I was able to create material using script file you suggested and using command.

    I have one more doubt related to programmatic execution, as I was trying this on student version if I move to licensed enterprise version will there be any python or java APIs available to do the same action ?

  • surajsalvi
    surajsalvi Member Posts: 5
    First Comment
    Options

    Hi Pernelle Marone-Hitz


    From the post you shared I can able to add material over the existing project successfully. Below is the command which I used :


    "C:\Program Files\ANSYS Inc\ANSYS Student\v222\Framework\bin\Win64\RunWB2.exe" -B -F "D:\Script\PROJECT_cust_matl.wbpj" -R "D:\Script\SCRIPT_create_matl.wbjn"


    And below is the script which I generated from the File -> Scripting -> Record Journal option in Ansys Workbench


    # encoding: utf-8
    # 2022 R2
    SetScriptVersion(Version="22.2.192")
    system1 = GetSystem(Name="SYS")
    engineeringData1 = system1.GetContainer(ComponentName="Engineering Data")
    matl1 = engineeringData1.CreateMaterial(Name="MATL-04")
    matlProp1 = matl1.CreateProperty(
      Name="Elasticity",
      Behavior="Isotropic",
      Qualifiers={"Definition": "", "Behavior": "Isotropic"})
    matlProp1.SetData(
      Index=-1,
      Variables=["Young's Modulus"],
      Values=[["85 [Pa]"]])
    matlProp1.SetData(
      Variables=["Poisson's Ratio"],
      Values=[["2"]])
    matlProp1.SetData(
      Variables=["Poisson's Ratio"],
      Values=[["0.1"]])
    matlProp1.SetData(
      SheetName="Elasticity",
      SheetQualifiers={"Definition": "", "Behavior": "Isotropic", "Derive from": "Young's Modulus and Poisson's Ratio"},
      Variables=["Temperature"],
      Values=[["35 [C]"]])
    Save(
      FilePath="D:/Scrip/PROJECT_cust_matl.wbpj",
      Overwrite=True)