0

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

Ali Asad
  • 1,235
  • 1
  • 18
  • 33

2 Answers2

1

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

Ali Asad
  • 1,235
  • 1
  • 18
  • 33
  • 2
    All of the points above are valid and well observed. If you need to "purge" the best way would be to perform your own collect + delete operations. Those are fully supported by Revit API. So if you wish to delete all unplaced Views for example, just collect them all, check if they are placed on sheets, and if not delete it. You probably noticed that invoking a revit command doesn't allow you to pass any arguments to it. It just brings up the window. Now, unless you want to get into nitty-gritty of clicking on buttons programmatically it's really a useless window. – konrad Nov 09 '17 at 16:41
1

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

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • Thank you for sharing it on the separate thread. Appreciate the support. Cheers !! – Ali Asad Nov 13 '17 at 05:20
  • 1
    Thank **you** Ali for the answer. I added a note to the blog post pointing back here as well, for the list of limitations you provide. Cheers – Jeremy Tammik Nov 14 '17 at 08:39