USer Event when user locks a View/ DesignViewReperesentation

USer Event when user locks a View/ DesignViewReperesentation

Holzethekid
Contributor Contributor
325 Views
2 Replies
Message 1 of 3

USer Event when user locks a View/ DesignViewReperesentation

Holzethekid
Contributor
Contributor

Hallo,

 

a am searching for an event on the api which tells me when a user locks/unlock  a view.

 

Holzethekid_0-1659897725058.png

 

What i found out so far is that the kDefaultCommand is executed when clicking the btn.

 

 

 

....
application.CommandManager.UserInputEvents.OnStartCommand += OnStartCommand;
....
private void OnStartCommand(CommandIDEnum commandid)
{
   logger.Debug($"OnStartCommand {commandid}");
}

 

 

So does any one know how to achieve this ?

My current solution would be : 

 

 

private void OnStartCommand(CommandIDEnum commandid)
{
    logger.Debug($"OnStartCommand {commandid}");

    if (app.ActiveDocument is PartDocument part)
    {
        foreach (DesignViewRepresentation designViewRepresentation in part.ComponentDefinition.RepresentationsManager.DesignViewRepresentations)
        {
            if (viewLockedStatus.ContainsKey(designViewRepresentation.Name))
            {
                if (viewLockedStatus[designViewRepresentation.Name] != designViewRepresentation.Locked)
                {
                    viewLockedStatus[designViewRepresentation.Name] = designViewRepresentation.Locked;
                    Messenger.Default.Send(new ViewLockStatusChangedMessage(designViewRepresentation.Name));
                }

            }
            else
            {
                viewLockedStatus.Add(designViewRepresentation.Name, designViewRepresentation.Locked);
            }
        }
    }
}

 

 

 

Thanks in advance

 

Christian 

0 Likes
Accepted solutions (1)
326 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

You should have at the OnDocumentChange event. It will fire on all changes. But you can check the context parameter it will tell you the internal name of the command that caused the change. (This name will be consistent regardless of the current language.)

Class MyClass

    Private appEvents As ApplicationEvents

    Sub Main()

        appEvents = ThisApplication.ApplicationEvents

        AddHandler appEvents.OnDocumentChange, AddressOf AppEvents_OnDocumentChange

    End Sub

    Private Sub AppEvents_OnDocumentChange(DocumentObject As _Document, BeforeOrAfter As EventTimingEnum, ReasonsForChange As CommandTypesEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum)
        HandlingCode = HandlingCodeEnum.kEventNotHandled

		If (Context.Item("InternalName") = "LockDesignView") Then
            MsgBox($"Someone clicked the lock button.")
        End If

    End Sub

End Class

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 3

Holzethekid
Contributor
Contributor

Hallo JelteDeLong,

 

thank you for your  answer. In my case the name changed to 'UCLockDesignView'.

The current snipped works on Inventor Pro. 2022.2  

private void OnDocumentChanged(_Document documentobject, EventTimingEnum beforeorafter, CommandTypesEnum reasonsforchange, NameValueMap context, out HandlingCodeEnum handlingcode)
  {
      if ((string)context.Item["InternalName"] == "UCLockDesignView")
      {
          Messenger.Default.Send(new ViewLockStatusChangedMessage("Bla"));
      }

      handlingcode = HandlingCodeEnum.kEventHandled;
  }

 

 

0 Likes