Author Topic: Lock/Unlock element via AddIn  (Read 1709 times)

phdare

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Lock/Unlock element via AddIn
« on: August 29, 2014, 04:39:25 pm »
I tried to lock/unlock element via AddIn. In EA_OnContextItemDoubleClicked (before properties dialog is opened). I add some code to lock element
      EA.Element element = Repository.GetElementByGuid(GUID);
      element.Locked = true;
but it didn't work, properties dialog open and element isn't locked.

qwerty

  • EA Guru
  • *****
  • Posts: 11388
  • Karma: +295/-262
  • I'm no guru at all
    • View Profile
Re: Lock/Unlock element via AddIn
« Reply #1 on: August 29, 2014, 04:58:38 pm »
Your code misses the Update, but I guess you just did not post that. So most likely this will not work. There are already quite some work arounds in the area of these OnPre/Post methods since they do not exactly behave as you expect (some would call it inconsistency, but I just call it poor design). So I recommend to send a bug report and look for an alternative solution :(

q.

phdare

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Lock/Unlock element via AddIn
« Reply #2 on: August 29, 2014, 05:36:57 pm »
If I add the Update method, I will get System.Runtime.InteropServices.COMException with message "Element Lock".
If I remove the Update, I need to close and reopen diagram afterward, the Element is locked. It seems element is updated without calling the Update. To walk around, I I add Repository.ReloadDiagram but it didn't work well, sometimes Sparx is crashed.
                :(

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 10406
  • Karma: +342/-30
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Lock/Unlock element via AddIn
« Reply #3 on: August 29, 2014, 06:36:25 pm »
Locking and unlocking with the API functions doesn't work.
I've posted my workaround on the forum a while ago.

(use top left search button to search)

Geert

Viking

  • EA User
  • **
  • Posts: 350
  • Karma: +1/-2
    • View Profile
Re: Lock/Unlock element via AddIn
« Reply #4 on: October 18, 2020, 02:04:12 am »
Locking and unlocking with the API functions doesn't work.
I've posted my workaround on the forum a while ago.
(use top left search button to search)
Geert

Could somebody tell me the link, please? I cannot find the workaround. V.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 10406
  • Karma: +342/-30
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Lock/Unlock element via AddIn
« Reply #5 on: October 18, 2020, 02:32:05 am »
Element.ApplyUserLock() works if the element was not locked yet
And Element.ReleaseUserLock() works if the current user was locking the element.

For other stuff you'll have to manipulate the database directly.

Geert

Viking

  • EA User
  • **
  • Posts: 350
  • Karma: +1/-2
    • View Profile
Re: Lock/Unlock element via AddIn
« Reply #6 on: Today at 04:34:35 am »
Element.ApplyUserLock() works if the element was not locked yet
And Element.ReleaseUserLock() works if the current user was locking the element.
For other stuff you'll have to manipulate the database directly.
Geert

Many thanks, Geert. I am using these methods by still getting "System.Runtime.InteropServices.COMException" with message "Element Lock". Are there also other reasons for this Exception, e.g. a write lock on the database for any reason?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 10406
  • Karma: +342/-30
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Lock/Unlock element via AddIn
« Reply #7 on: Today at 05:04:32 am »
In which circumstances do you get that message?
If you share your code we can maybe spot where it goes wrong.

Geert