Besides the need to create objects by scripts, there is obviously also the need to delete objects. However, deletion is a critical action in a tool, there might be dependencies that need to be handled or even things that prevent deletion. For that reason we intentionally disabled any deletion or rearrangements via the scripting API in the beginning.
Similar to the Factory we then started to provide a script library that supports the deletion of objects and models to come closer to what is needed to delete stuff and to a deletion API. This trashbin.js called library has been used in a few scripts now with mixed results. The main problem is still that deletion needs a careful hand so any script that deletes any object has to make sure that it does things right. An example:
// delete the selected element
if (selection && selection.length == 1) {
Trashbin.deleteElement(selection[0]);
}
This snippet simply deletes any selected element without checking it. This may cause serious damage to the project, stated as simple as that. For example, the tool does not allow the deletion of elements in FMEA worksheets, they are derived from system elements. In addition, when deleting system elements, also their "proxies" in FMEA worksheets are deleted, the user is notified about that and has to confirm. The trashbin.js library has no support for that. However, a few basic consistency rules are always followed when deleting elements:
- traces to or from a deleted object are removed too
- same holds for relationships, connectors etc.
- contained elements are recursively removed
The library in its latest version is attached to this topic. Note that this version copes correctly with model objects in contrast to previous versions of the library.