Delete material in the Material folder inside Mechanical

Erik Kostson
Member, Moderator, Employee Posts: 314
✭✭✭✭
How can we delete a material (say Structural Steel) in the Materials folder inside Mechanical?
0
Comments
-
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()
0 -
To delete all of the materials except of one (matk called below):
import wbjn model = ExtAPI.DataModel.Project.Model materials=model.Materials.Children matk="Structural Steel" # material to keep change as needed for mat in materials: if mat.Name !=matk: name=str(mat.Name) print(name) ScriptCmds = """ system1 = GetSystem(Name="SYS") engineeringData1 = system1.GetContainer(ComponentName="Engineering Data") matd = engineeringData1.GetMaterial(Name="%s") matd.Delete() """%name wbjn.ExecuteCommand(ExtAPI, ScriptCmds) Model.RefreshMaterials() ExtAPI.DataModel.Tree.Refresh()
0
This discussion has been closed.