Book a Demo

Author Topic: Applying Full Lock with API  (Read 3126 times)

BrianYee

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Applying Full Lock with API
« on: January 05, 2021, 09:00:36 am »
Hello,

Is there a way to apply a full lock on a diagram/element/package (no one may edit without first removing the lock) by using the API?
I'm writing a script to lock a diagram for all users, but ApplyUserLock() and ApplyGroupLock() are only for user and whichever security group in the parameter.

Regards,
Brian

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Applying Full Lock with API
« Reply #1 on: January 05, 2021, 09:42:37 am »
Look at Repository.ApplyGroupLockRecursive (and the other ones).

There's a hacky way to lock just diagrams. Here's an excerpt of my Python code:
Code: [Select]
actionCount = 0
for elementId, style, guid in rep.query("SELECT object_id, style, ea_guid FROM t_object WHERE package_id in (%s)" % ", ".join(packages)):
    style = repository.EACSV(style)
    lock = style.attr("Locked")
    val = ["false", "true"][action]
    if lock != val: style.setAttr("Locked", val)
    if style.changed:
        actionCount += 1
        if args.verbose: logger.log("I1GUID", guid)
        rep.execute('UPDATE t_object SET style="%s" WHERE object_id=%s' % (style.csv, elementId))
(will only work with my lib included but the principle should be obvious)

q.