Script for deleting selected workbench systems.
Answers
-
The below script works at the project page level.
#Enter the systems to be deleted systems2Delete = ["C","D"] from collections import defaultdict systemsData = defaultdict(list) systems = GetAllSystems() for system in systems: component1 = system.Components[0] systemsData[ACT.InitializeAndGenerateTaskCoordinates(component1)[0]] = system #Sorting is required since after every delete systems get re-named #Therefore deleting the systems in reverse order sortedValues = systemsData.keys() sortedValues.sort() sortedValues.reverse() from collections import OrderedDict OrderedData = OrderedDict() for value in sortedValues: OrderedData[value] = systemsData[value] for key in OrderedData: if key in systems2Delete: OrderedData[key].Delete()
1 -
Is it possible to apply the same code based not on a systems2Delete list but based on the actual selected SYSs in Workbench?
0 -
I don't think we can retrieve selected SYS from the WB project page, but maybe someone from the @AKD-Scripting-Team knows how.
0 -
I don't think there is a way to retrieve selected Sys from WB Project Page. I would suggest making a python list containing strings of names of all the systems, loop through all systems, and use an if condition based on Sys.Display text to filter the systems one would need to operate on.
1 -
You can GetAllSystems and then use the [n].Name to delete a system by name.
systems = GetAllSystems() system1 = GetSystem(Name=systems[0].Name) system1.Delete()
If you need to limit or filter, you can use the system.DisplayText() which is the name of the component in WB.
1 -
import System import clr clr.AddReference("Ans.UI") import Ansys.UI uiMgr = Ansys.UI.UIManager.Instance psView = uiMgr.GetActiveWorkspace().GetView("ProjectSchematic") d = psView.Control selectedCells = [] for taskGroupBlock in d.Blocks: for taskBlock in taskGroupBlock.Cells: if taskBlock.Selected: selectedCells.append(taskBlock) for selectedCell in selectedCells: tag = selectedCell.Tag t = tag.GetType() entityProp = t.GetProperty("Entity", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public) component = entityProp.GetValue(tag) for system in GetAllSystems(): if component in system.Components: system.Delete()
2 -
Thanks!
0