Skip to content

Instantly share code, notes, and snippets.

@initialed85
Last active February 7, 2023 17:37
Show Gist options
  • Save initialed85/a1aacfb1641f2d1b2866adebead66869 to your computer and use it in GitHub Desktop.
Save initialed85/a1aacfb1641f2d1b2866adebead66869 to your computer and use it in GitHub Desktop.
Example Jython script for NoMagic MagicDraw (Cameo Systems Modeler) metachain navigation
import pprint
def log(thing): # append to a log file
if not isinstance(thing, str):
text = repr(thing)
else:
text = thing
try:
f = open('/tmp/something.log', 'a')
f.write(text.rstrip() + '\n')
f.close()
except:
pass
def dump(obj, indent=0): # dump info about an object to the log file
spacing = ' ' * indent
for k in dir(obj):
if not k.startswith('get'):
continue
if k not in ['getHumanType', 'getName', 'getQualifiedName', 'get_directedRelationshipOfSource', 'get_directedRelationshipOfTarget', 'getSource', 'getTarget', 'getLocalID']:
continue
v = getattr(obj, k)
try:
data = v()
if data is not None and len(data) > 0:
log(spacing + k + ' = ' + str(len(data)) + ' = ' + repr(data))
except:
pass
log('\n')
log(obj)
log('\n')
log(type(obj))
log('\n')
log('----\n\n')
contexts = []
# log('\n!!!!\n')
# log('arg1')
# dump(arg1)
for b in arg1.get_directedRelationshipOfSource():
# log('b')
# dump(b, 4)
for c in b.getTarget():
# log('c')
# dump(c, 8)
for d in c.get_directedRelationshipOfTarget():
# log('d')
# dump(d, 12)
if d.getHumanType() != 'Verify':
continue
for e in d.getSource():
# log('e')
# dump(e, 16)
if e.getHumanType() != 'Test Scenario':
continue
contexts += [
(
e.getName(),
e.getHumanType(),
e.getID(),
e.getLocalID(),
e.getQualifiedName(),
),
]
log(pprint.pformat(contexts))
result.set([
repr([x[0], x[3]]) for x in contexts
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment