However, Revit can only filter elements according to family categories, while Grasshopper can filter by parameters more accurately, and create selection sets directly after filtering, and reload the selection sets directly in Revit when necessary.
For example, to filter all walls whose annotation parameter is Room, you can select all walls first, and then filter according to the parameter:
At the same time, create a parameter filter to filter the parameter value of "Annotation" to "Room", and then merge the two filters through a "LogicalAndFilter" node:
In this way, through the "QueryElements" node, it is easy to filter out the required walls according to the previous two filters:
This step is smooth, but when you want to create a selection set, you find that there are no ready-made nodes in the node library to create a selection set. At this time, you can only query the API to see if it can be solved by code:
So open the RevitAPI manual and search the method of ionFilterElement, and we can see:
Finding the creation method is very simple, and the basic grammar is super simple, which can be directly applied:
selset=ionFilterElement。 (Document, Name)
But actually writing it down, I found that there are still many problems to pay attention to:
One is that when creating a selection set, it is necessary to judge whether there is a selection set with the same name in the project, because there is a selection set with the same name that cannot be created. There is no need to delete the selection set here, just empty the selection, and then you can add the selected primitives;
The other is that the newly created selection set is empty and the selected elements need to be added to it. The method used is: AddSet, the syntax is as follows:
If you think these two questions clearly, you can write the code smoothly. The complete code is as follows:
#Copyright(c)2020, Jiuge Bimerimportclrclr.addreference ('system.core') clr.addreference ('rhinoinside.revit') clr.addreference ('revit API') clr.addreference ('revitapiui'). fromSystemimportEnum,actionimportrhinoscriptsyntaxasrsimportrhinoimportrhinoinsideimportgrasshopperfromsgrasshop。 KernelimportGH _ runtimemessagelevelasmlfromrinoinside。 Re vitimportRevit, Convert# can also add an extension method # which allows calling. ToXXX () converter method clr. importextensions (convert。 Geometry). Revimeportdbfromdesk.revit.dbimport * # on the revit object. Access the active document object doc=Revit. ActiveDBDocument# to filter the primitive ids=list()ifnotisinstance(E, List): e = [e] else: e = eforeine: ids. Append (e.id) itemset = set (ids) # Collect all existing filters from the model Names = list () collector = FilterDeletementCollector (doc) Filters = collector. Class (filterelement). To element. Selset = false set = transaction (doc,' create selection set') t.Start()# If a selection set with that name already exists, Then delete its contents for filtering filters: iffilter.name = = name: filter.clear () selset = filter # Create a new selection set (if the selection set does not exist) if selset = = false: selset = ionfilterelement. (Doc, Name)# Adds the selected primitive to the selection set try: selset. addset (itemset) out = selset。 todsttype(false)except:out = nonet。 Commit () print (out) There are several steps to write code:
1. Collect the primitives to be added to the selection set and get the ID list;
2. Get the selection set in the model.
3, judging whether the selection set in the model and the selection set to be created have the same name;
4. If there is a selection set with the same name, please empty the selection.
5. If there is no selection set with the same name, create a new selection set.
6. Add the filtered primitives to the selection set.
Finally, put a full picture of the filter wall and add a selection set for your reference: this is the "Method Course of Creating Selection Sets and Search Sets in Revit". After reading the above, do you know anything about creating selection sets and search sets? Pay attention to learn more about the graphic tutorial "Article".