ElementType with BackgroundOpen

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

image

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

In order to work with background open documents you need to limit yourself to nodes which have a document input.

Since background opening documents isn’t supported by any of the standard nodes this limits you to Python and custom node based solutions.

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

So i’ve just run across a weird problem

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

Any idea why walls wouldn’t be pulled?

Initial Script

		collector = FilteredElementCollector(doc)
		
		listed.append(FilteredElementCollector(doc).OfClass(FamilyInstance).OfCategoryId(i.Id).WhereElementIsNotElementType().ToElements() )
		listed.append(FilteredElementCollector(doc).OfClass(CeilingAndFloor).OfCategoryId(i.Id).WhereElementIsNotElementType().ToElements() )

Added walls collector

		collector = FilteredElementCollector(doc)
		
		listed.append(FilteredElementCollector(doc).OfClass(FamilyInstance).OfCategoryId(i.Id).WhereElementIsNotElementType().ToElements() )
		listed.append(FilteredElementCollector(doc).OfClass(CeilingAndFloor).OfCategoryId(i.Id).WhereElementIsNotElementType().ToElements() )
		listed.append(FilteredElementCollector(doc).OfClass(Wall).OfCategoryId(i.Id).WhereElementIsNotElementType().ToElements() )