-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_association_by_name.py
More file actions
38 lines (29 loc) · 1.11 KB
/
Copy pathdelete_association_by_name.py
File metadata and controls
38 lines (29 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
Modelio Jython Script to delete an Association by name in the selected package.
"""
from org.modelio.metamodel.uml.statik import Class, Association
TARGET_NAME = "Edge_Node_1_to_Fog_Node_1"
if elt is None or not isinstance(elt, Class):
print("Error: Please select any node to identify the package.")
else:
parent_package = elt.getOwner()
print("Deleting association named: " + TARGET_NAME)
print("Package: " + parent_package.getName())
transaction = session.createTransaction("Delete Association By Name")
try:
deleted = 0
for element in parent_package.getOwnedElement():
if isinstance(element, Association):
if element.getName() == TARGET_NAME:
element.delete()
deleted += 1
transaction.commit()
if deleted == 0:
print("No association found with that name.")
else:
print("Deleted " + str(deleted) + " association(s).")
except Exception as e:
transaction.rollback()
print("Error: " + str(e))
import traceback
traceback.print_exc()