i’m trying to clean up Revit model to be used as project template, lots of junks which are invisible like ref plane, etc
just thinking if i can get all element instances via Python, then i can delete them …, turned out a few issues:
how to convert category from cats to category from bics? seems cats is much less than bics and cats are more “suitable” in my case
cats = doc.Settings.Categories
bics = System.Enum.GetValues(BuiltInCategory)
seems the elements below are not all instance elements? some are type elements like line type, group type, etc
elements = FilteredElementCollector(doc).WhereElementIsNotElementType().OfCategory(bic).ToElements()
For the second point I don’t know. To select elements in dynamo with OOTB nodes i normally use a combination of ElementTypes (=FamilyInstance) -> All Elements of Element Type but I guess with your API method its more complete. To filter out “bad” elements maybe you should find all the types you dont want (str(item.GetType())) and filter out that way?
Anyways did you already purge the model before running dynamo?
category from doc.Settings.Categories is not same as category from IN[0] which is actually BuiltIn already (at first i thought category from IN[0] is same as from doc.Settings.Categories).
purge will purge element type only which is not desired, well, as you know that project template needs to preload many types.
Excuse me but I do not understand what type of categories you want
OUT = UnwrapElement(IN[0])
I think that the dynamo nodes give you some wrapped objects, while python is able to unwrap them.
With doc.settings.Categories and with UnwrapElement you get a Revit.DB.Category, instead with System.Enum.ToObject(BuiltInCategory,etc you get a Revit.DB.BuiltInCategory.
Or are you trying to select all builtin categories? Please excuse me if I do not understand correctly!
As for the purge you can manually choose what to delete and what to keep, obviously by hand. In Dynamo you could filter the elements you do not want to delete with str(item.GetType()) logic as I said in my previous post, or you could check if they have a location…maybe elements that are not instances do not have a location?
The python output belongs to the Revit API namespaces, while BoundingBox.ToCuboid (and all elements of category) wants an input belonging to the “dynamo namespace” or seomthing like that. I am not sure if you can convert a revit boundingbox to a dynamo one (you could however export the points and create a bounding box with the dynamo nodes)
for boundingbox issue, solution by Thomas_Mahon as below:
That’s because you’re calling Dynamo’s Revit Element wrapper method. If you are looking to return ProtoGeometry try ToProtoType() instead.
currently i’m having troubles in connection between Python and Dynamo so need more research on it, especially when and how to use ToDSType, ToRevitType, ToProtoType, anything else?