Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Revit 2013 - Command Binding

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
grahamcook
1123 Views, 3 Replies

Revit 2013 - Command Binding

Hi

I'm looking at the new AddInCommandBinding class which is a great addition to the Revit 2013 API.  This allows us to replace revit commands with our own actions.  Within that action i would like to be able to check for a condition and if that condition is true then implement my custom function else let Revit run the original revit command as normal.

So if the Executed event of any given commandId was bound to myCustomAction the following would apply:

 

private void myCustomAction(object sender,  Autodesk.Revit.UI.Events.ExecutedEventArgs e)
{
    // condition logic here
    // bool condition = false;
    // etc
    //------------------------

    if (condition == true)
    {
        // run custom function / routine / popup / etc
    }
    else
    {
        // run command as normal
    }
}

It's the "run command as normal" bit that i can't figure out but i'm not even sure if the current version of the 2013 API supports this flexible approach??

 

3 REPLIES 3
Message 2 of 4
adam.nagy
in reply to: grahamcook

Hi there,

 

As I understand the only thing you can do is completely replace a command with your own implementation. You cannot combine your functionality with the original functionality or switch between original and new implementation when the command is called.

 

This is what this comment seems to be suggesting as well here: 

"Note that you cannot call an existing command, just replace it entirely."

http://thebuildingcoder.typepad.com/blog/2012/06/replacing-built-in-commands-and-their-ids.html

 

______________________________________________________________

If my post answers your question, please click the "Accept as Solution"

button. This helps everyone find answers more quickly!



Adam Nagy
Autodesk Platform Services
Message 3 of 4
peterjegan
in reply to: grahamcook

I have been looking into this concept also, but I haven't gotten very far yet.

 

The AddInCommandBinding takes place in the OnStartup event of the application. What if you intercepted the process on definition, maybe like this:

 

   public Result OnStartup( UIControlledApplication app )

    {

  AddMenu(app);

  // look up the command id

  s_commandID = RevitCommandId.LookupCommandId(s_commandToDisable);

  if (!s_commandID.CanHaveBinding)

  {

   MessageBox.Show("The target command "+ s_commandToDisable + " cannot be overridden.");

   return Result.Failed;

  }

 

  try

  {

   if (MyCustomSecurity == true)  

   {

   AddInCommandBinding cBinding = app.CreateAddInCommandBinding(s_commandID);

   cBinding.Executed += DisableEvent;

   }

  }

  catch (Exception)

  {

   MessageBox.Show("Cannot disable " + s_commandToDisable + "; most likely another command had overridden this command.");

  }

    return Result.Succeeded;

    }

Message 4 of 4
grahamcook
in reply to: grahamcook

Peter

Yes, I've thought of that approach.  Problem is in this case I am replacing the edit family command (or was trying to - see below thread).  So the security check would return a different answer everytime based on the particular family name the user is editing - ie some are protected, some aren't.  But your suggested approach would work for session wide conditions.  I resolved my problem as per the following thread:

 

http://forums.autodesk.com/t5/Autodesk-Revit-API/Edit-Family-Command-ID/m-p/3562798#M2881

 

But I think being able to interrupt a command at the very beginning and then either letting it go or replacing with your own flow would be a useful addition in future releases.  Perhaps a wish list item?

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community