Delete material in the Material folder inside Mechanical

Erik Kostson
Erik Kostson Member, Employee Posts: 233
50 Answers 100 Comments Second Anniversary 25 Likes
✭✭✭✭
edited November 2023 in General Language Questions

How can we delete a material (say Structural Steel) in the Materials folder inside Mechanical?

Comments

  • Erik Kostson
    Erik Kostson Member, Employee Posts: 233
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited November 2023

    This is not possible to do, either manually (say by RMB on that material in that folder and choose delete) or via pure mechanical scripting it seems like.

    One way of doing this is though via wbjn workbench scripting inside the mechanical script console. The following sample code deletes the Structural Steel material in the Materials folder (and Engineering Data) of the first system in the workbench project (SYS).

    import wbjn
    ScriptCmds = """
    system1 = GetSystem(Name="SYS")
    engineeringData1 = system1.GetContainer(ComponentName="Engineering Data")
    material1 = engineeringData1.GetMaterial(Name="Structural Steel")
    material1.Delete()
    """
    wbjn.ExecuteCommand(ExtAPI, ScriptCmds)
    Model.RefreshMaterials()
    ExtAPI.DataModel.Tree.Refresh()
    
This discussion has been closed.