Announcement

Collapse
No announcement yet.

How to handle the firing of a Revit command with CommandEventArgs C#

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to handle the firing of a Revit command with CommandEventArgs C#

    I would like to be able to register which commands are being used within the Revit aplication C#.
    To do so, I am trying with the CommandEventArgs.

    I know that it is possible to register when the RevitCommandId is the same as e.g. "ID_OBJECTS_WALL" by using the ExecutedEventArgs:


    AddInCommandBinding importBindingID_OBJECTS_WALL = application.CreateAddInCommandBinding(RevitCommand Id.LookupCommandId("ID_OBJECTS_WALL"));
    importBindingID_WINDOW_CLOSE_HIDDEN.Executed += new EventHandler
    <Autodesk.Revit.UI.Events.ExecutedEventArgs>((send er, arg) => application_Command(sender, arg, "ID_OBJECTS_WALL"));


    However, I would like to register ANY command that the user fires and thus, it's not very feasible to use the ExecutedEventArgs with AddInCommandBinding for all Revit commands (+1200).

    To do so, I am trying with the CommandEventArgs:

    UIControlledApplication.CreateAddInCommandBinding( RevitCommandId) += new EventHandler
    <Autodesk.Revit.UI.Events.CommandEventArgs>(applic ation_Command);


    But I am not sure which namespaces and classes to use, to successfully handle this event, I'm not sure if I should use the UIControlledApplication, I'm not sure if I should use the CreateAddInCommandBinding. I have been looking at the Revit Api Docs but I couldn't figure it out.

    Is it possible to register ANY command with the CommandEventArgs or the ExecutedEventArgs?
    How can I achieve that?

    Any help would be appretiated.
    Last edited by ritaaguiar; September 27, 2018, 09:47 AM.

    #2
    you can try using Autodesk.Revit.ApplicationServices.Application.Doc umentChanged
    You get at least the transaction names involved.

    By the way, are you trying to establish a communist style revit control in the office?
    Gonçalo Feio
    "Ignorance, ignorance, sheer ignorance - you know there's no confidence to equal it. It's only when you know something about a profession, I think, that you're timid and careful." George Orson Welles

    Comment


      #3
      Hi @feio
      Thank you for your suggestion! I will try that too.

      I am creating a plugin to register people's use of several applications in the office I work at. Besides Revit I already created a similar plugin for AutoCAD and CIVIL 3D with the same intent. The goal is to control the use of the licenses the office is purchasing.

      Comment


        #4
        You may like to look at ******* from ********. Whilst not listing the commands used it does keep track of Active time spent in software. e.g. Photoshop, Revit, AutoCAD. The person that insists they must have Photoshop can be assessed as to whether they actually use the software day to day.
        Last edited by Munkholm; November 21, 2018, 05:44 AM. Reason: Spam Removed (****)

        Comment


          #5
          Originally posted by aricke View Post
          You may like to look at ******** from *******. Whilst not listing the commands used it does keep track of Active time spent in software. e.g. Photoshop, Revit, AutoCAD. The person that insists they must have Photoshop can be assessed as to whether they actually use the software day to day.
          Thank you for your reply.

          (https://forums.autodesk.com/t5/revit...8338033#M34137)

          Unfortunately it is not possible to register any command in Revit.
          So I ended up doing this method:

          public void application_DocumentChanged(Object sender, DocumentChangedEventArgs args_changed)
          {
          // get document from event args_changed.
          Document doc = args_changed.GetDocument();

          // dump the element information
          ICollection<ElementId> addedElem = args_changed.GetAddedElementIds();
          foreach (ElementId id in addedElem)
          {
          DumpEventArgs(id, doc, "Added");
          }

          ICollection<ElementId> deletedElem = args_changed.GetDeletedElementIds();
          foreach (ElementId id in deletedElem)
          {
          DumpEventArgs(id, doc, "Deleted");
          }

          ICollection<ElementId> modifiedElem = args_changed.GetModifiedElementIds();
          foreach (ElementId id in modifiedElem)
          {
          DumpEventArgs(id, doc, "Modified");
          }

          }And I also used

          elem.Category.Name to identify which element in being added or modified.

          to retrieve this:
          private void DumpEventArgs(ElementId id, Document doc, string changeType)
          {
          Element elem = doc.GetElement(id);

          if (elem == null)
          {
          // this branch is for deleted element due to the deleted element cannot be retrieve from the document.

          MessageBox.Show($"The user {Environment.UserName} edited a document: {changeType} of unknown category");
          }

          else
          {
          MessageBox.Show($"The user {Environment.UserName} edited a document: {changeType} {elem.Category.Name}");
          }
          }
          Last edited by Munkholm; November 21, 2018, 05:44 AM.

          Comment


            #6
            An option in ******* ( with workshared files) is to monitor and set parameters as to who changes items and when they were changed - this can be useful when trying to track down whose work practices are creating issues in your projects. This uses a similar approach to what you have opted to do.

            If you really want to get specific about the commands being used you can process the "journal files". It would require a fair amount of parsing of the file to get intelligent results but it would readily supply the information you are after. This could actually be run quite externally to Revit and could be done hourly, daily or weekly. This would be a relatively straight forward programming task.
            Last edited by Munkholm; November 21, 2018, 05:44 AM. Reason: Spam Removed (****)

            Comment

            Related Topics

            Collapse

            Working...
            X