Deleting a Global Parameter and RevitPythonShell

This is another entry in the list of my attempts at teaching Revit API developers how to fish instead of feeding them. Mostly, it ends up a mixture between the two, of course:

This time, we address the question on how to:

Deleting a Global Parameter

Question: I have list of all global parameters from the active Revit document. I want to delete a specific global parameter from the list programmatically. Kindly suggest a way to delete a global parameter from the active document.

Answer: Thank you for your query.

You can easily answer this question yourself, you know.

I did not know either, on first reading your question.

Here is the path I took to search for an answer:

I initially searched the Internet for 'revit api delete global parameter'.

This led to some non-API discussions, such as the one by RevitCat on Deleting Global Parameters in Revit.

It also led to the official developer guide discussion on managing global parameters.

There, I learned that this is achieved programmatically using the GlobalParametersManager class.

It does not provide any method to delete a global parameter.

However, the access to global parameters is provided by the FindByName method.

That method simply returns an element id.

This means that each global parameter is stored in the document database as a normal Revit element.

This means that it can be deleted using the Document.Delete method taking an ElementId or a collection, just like any other Revit element.

Testing Using RevitPythonShell

I decided to try this out on the fly using RevitPythonShell.

I did not have it installed previously, but that can be achieved in seconds with a single click on the RevitPythonShell installer.

I then launched Revit and created a global parameter manually through the user interface:

Global parameter

Next, I started the interactive Python shell and ran the following code:

from Autodesk.Revit.DB import *
doc = __revit__.ActiveUIDocument.Document
id = GlobalParametersManager.FindByName(doc,'Test')
t = Transaction(doc)
t.Start('delete gp')

Immediately after running this code, the global parameter is no longer listed in the user interface.

I trust this solves your issue.