Getting RevitCommandID for any commands users executes

Getting RevitCommandID for any commands users executes

Anonymous
Not applicable
2,119 Views
13 Replies
Message 1 of 14

Getting RevitCommandID for any commands users executes

Anonymous
Not applicable

Hi Everyone,

 

after doing some research I couldn't find the answer to my question and I was hoping I can get some help from people here.

I have parsed a large number of Revit journals and have extracted the RevitCommandIds from it based on user name and project name. I have trained a machine learning model to predict what would be the next command based on a given sequence.

 

Now I want to integrate my machine learning model with Revit such that I can get the RevitCommandId (e.g "ID_EDIT_MOVE" or "ID_FINISH_SKETCH" ) as the user executes the commands and feed that string to my prediction function and get a prediction for the next commands.

 

The question I have is if there any ways that I can listen to command execution and get RevitCommandID, I taught of command binding but it is not feasible to do that for 500+ commands I have recorded and there will be some performance issues also as far as I understand it can be used with portable commands.

 

 

I have already looked into these links but I couldn't figure out a way:

 

building coder(Command ID )

Revit Forum (IUpdater) 

Revit Forum ( Same question Unresolved) 

I would appreciate any suggestions.

 

0 Likes
2,120 Views
13 Replies
Replies (13)
Message 2 of 14

jeremy_tammik
Alumni
Alumni

Wow! That sounds like a really exciting project!

  

Don't know whether this will help...

  

The DocumentChangedEvent enables you to determine the transaction names using the GetTransactionNames method:

 

https://www.revitapidocs.com/2021.1/bc13391a-66bd-1530-3d08-f1b48a460416.htm

 

This enables detecting launch and completion of specific commands:

 

https://thebuildingcoder.typepad.com/blog/2020/01/torsion-tools-command-event-and-info-in-da4r.html#...

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 14

RPTHOMAS108
Mentor
Mentor

There is an event in AdWindows you can subscribe to which will give you the ids similar to how they appear in the journal but it only covers UI clicks:

Autodesk.Windows.ComponentManager.ItemExecuted
Autodesk.Internal.Windows.RibbonItemExecutedEventArgs
Autodesk.Internal.Windows.RibbonItemExecutedEventArgs.Item.Cookie

 

If you use context menu you don't get the above. AdWindows is also not part of the API so is used without guarantees of stability or fitness for purpose attached.

 

There is no secret if I place a beam the next command is often to place a second beam then a third...On some other occasion I'll be doing the walls or foundations perhaps.

0 Likes
Message 4 of 14

Anonymous
Not applicable

Thank you Jeremy for your quick response,

I am just experimenting with different things to see how data recorded in journals be of use other than troubleshooting.

I looked into transaction names and I was wondering if is there enumerable transaction names like the one for postable commands?  If I couldn't find a way to get the command IDs I am going to try pairing transaction names with command IDs if there is any relations between these two.

0 Likes
Message 5 of 14

Anonymous
Not applicable

Thanks for the info I will look into those events and methods.

About the prediction you are right, there are some obvious next moves based on the context and it is easy for us, humans to predict but I am just experimenting with different things such as predicting errors or failures, recommending better workflows and etc.

0 Likes
Message 6 of 14

sankar_g
Enthusiast
Enthusiast

Hi,

I think the below code will help you to get the active command id.

var cmdId = UIFrameworkServices.CommandHandlerService.getActiveCommandId();

Message 7 of 14

Anonymous
Not applicable

Thanks for the reference , Do you know where I can find documentation on UIFrameworkServices ? and what would be a proper event to subscribe to?

0 Likes
Message 8 of 14

Anonymous
Not applicable
from pyrevit import HOST_APP, framework
from pyrevit import revit
from pyrevit.framework import clr
clr.AddReference('UIFrameworkServices')

import UIFramework
import UIFrameworkServices


def event_handler_function(sender, args):

    transName=args.GetTransactionNames()
    commandID=UIFrameworkServices.
    CommandHandlerService.getActiveCommandId()
    print(transName)
    print(commandID)


HOST_APP.app.DocumentChanged  += \
    framework.EventHandler[DocumentChangedEventArgs](
        event_handler_function
        )

 

I'm using pyrevit because machine learning libraries I am using are in python and I know python more in general.

This is how I was subscribing to documentChanged event and I was getting transaction names but when I don't get anything for the getActiveCommandID. any help is much appreciated.

Message 9 of 14

frankholidayjunior
Advocate
Advocate

I wonder if this can be used to monitor which addins are being used, to get an idea of their usefullness.

0 Likes
Message 10 of 14

frankholidayjunior
Advocate
Advocate

thanx,

this solves my problem.

i just need to prefix my transactions with the addin name

0 Likes
Message 11 of 14

Anonymous
Not applicable

For that kind of analytics, I think looking at journals would be an easier way. I remember seeing a a post with similar topic on builduing coder.

0 Likes
Message 12 of 14

frankholidayjunior
Advocate
Advocate

thanx Aradnia

0 Likes
Message 13 of 14

frankholidayjunior
Advocate
Advocate

yes works fine as long as your namespace is well structured you can use to filter the string as its a mess otherwise

 

0 Likes
Message 14 of 14

sankar_g
Enthusiast
Enthusiast

There is no documentation for UIFrameworkServices.

I haven't worked with pyRevit. I am sure the getActiveCommandId() method is working fine with C# API. 

0 Likes