Pulling my hair out as to why my script wouldn’t work
Element.ElementType doesn’t work with elements collected in a background open
Node works perfectly fine if run in the current document
Can any shed some light on to how I will get around this?
I am trying to collect all placed families and output a type list
Have cycled through all the categories and created an instance list of only the placed families. Just cant figure out how to get the type information now
doc = IN[0]
categories = doc.Settings.Categories
model_ele = []
model_catname = []
for c in categories:
if c.CategoryType == CategoryType.Model:
if c.SubCategories.Size > 0 or c.CanAddSubcategory:
collector = FilteredElementCollector(doc)
elements = collector.OfCategoryId(c.Id).WhereElementIsNotElementType().ToElements()
if len(elements) > 0:
model_catname.append(c.Name)
model_ele.append(elements)
OUT = model_catname, model_ele
Check your list of Elements for odd things specifically of Curtain wall millions because some of them produce nulls and break the node as the error message says. I have experienced this before, just don’t recall exactly why elements caused it, but if you filter them first it should work.
This may also help you as I have done something similar and shared it before.
Thanks @SeanP…bits in your code in your other post helped to better collect elements
Also ran across a node in the Orchid package that solved a heap of issues
Element.ElementType that has a document input
doc = IN[0]
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
#create workset collector
userCategories = doc.Settings.Categories
#extract workset's name and ids
ids = []
for i in userCategories:
if i.CategoryType == CategoryType.Model:
if i.SubCategories.Size > 0 or i.CanAddSubcategory:
try:
ids.append(i.Id.IntegerValue)
except:
ids.append(0)
#Assign your output to the OUT variable
builtInNames = []
for x in ids:
try:
builtInNames.append(System.Enum.ToObject(BuiltInCategory, x))
except:
pass
listed = []
for z in builtInNames:
try:
listed.append(FilteredElementCollector(doc).OfClass(FamilyInstance).WhereElementIsNotElementType().OfCategory(z).ToElements())
listed.append(FilteredElementCollector(doc).OfClass(CeilingAndFloor).WhereElementIsNotElementType().OfCategory(z).ToElements())
except:
pass
OUT = listed
I noticed that in one model it wasn’t pulling out the wall elements, multiple other models it has worked fine. For this particular model I needed to add another element collector specifically collecting walls