Ali Asad
Ali Asad

Reputation: 1315

How to Call Revit Purge Button from the Revit API

I'm developing a plugin to detached a document from central and when its done it will be purged as well. I'm struggling writing the code for purge, I'm thinking to call the Revit Purge button from the code. If it is possible, would appreciate the support or maybe share the code for writing the purge command in the API.

Thank you

Upvotes: 0

Views: 1265

Answers (2)

Jeremy Tammik
Jeremy Tammik

Reputation: 8294

The Building Coder provides a summary of some purge examples in the discussion of purge and detecting an empty view.

Upvotes: 1

Ali Asad
Ali Asad

Reputation: 1315

With some research I have come up with the solution but it comes with few limitations too. We can call the Revit buttons from the API, including Purge.

Limitations:

  • You can't call a button from half way through your plugin.
    • You have to set it up to run after your plugin is done.
    • You might be able to get around this with subscribing to the Executed event but I'll need to experiment with that.
  • You don't know whether the command will run successfully.
    • Also, as you can't run it half way through your program, you have no way of checking whether it's succeeded within code.
    • You can check the journal logs and parse the result of the latest command but that's a very hack-y feeling solution.
  • You don't know ahead of time whether someone else has overridden the button to do something else.
    • The call is to just press the button. The article above focuses on overriding buttons. You can't guarantee that the button still does what you're expecting it to.
  • The process you trigger by pressing the button cannot be automated.
    • Your script has to finish before the button is pressed so you can't take control of the resulting dialogs.
    • You may be able to subscribe to the button events and fiddle something that way. Again, experimentation needed.

Following is the sample code to achieve this:

        UIApplication uiapp = commandData.Application;

        //Store the ID of desired plugin button, in this case its 'purge unused'
        String s_commandToDisable = "ID_PURGE_UNUSED";
        RevitCommandId s_commandId = RevitCommandId.LookupCommandId(s_commandToDisable);

        //This revit button will run at the end of your application. 
        uiapp.PostCommand(s_commandId);

To find list of default revit command id, click here

Upvotes: 1

Related Questions