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:
- Creating a group and how to fish
- Teaching a man how to fish and schedule creation
- Trusted signature motivation and fishing
This time, we address the question on how to:
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:
It also led to the official developer guide discussion on managing global parameters.
There, I learned that this is achieved programmatically using
It does not provide any method to delete a global parameter.
However, the access to global parameters is provided by
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.
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:
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') doc.Delete(id) t.Commit()
Immediately after running this code, the global parameter is no longer listed in the user interface.
I trust this solves your issue.