How can I know if an element can create an assembly with python in Dynamo for Revit?

How can I know if an element can create an assembly with python in Dynamo for Revit? Is there any Revit API thing to know this? If find this very difficult. I tried this: AreElementsValidForAssembly but I do not see any result.

Can you show us what you tried? Were there any errors?

I tried to filter the input elements by many conditions, even doing that I cannot believe some MEP elements like Ducts, Pipe Insulations appear without geometry in Revit, so they are not even visible and cannot be added in assembly, but they exist.

to know that I asked to get the bounding box so those elements do not have it, but even doing that I still get this warning, and sometimes the script creates the assembly but I get the warning anyway, Dynamo is kidding me here for sure

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. 
Traceback (most recent call last):
  File "<string>", line assembly_instance = AssemblyInstance.Create(doc, idlist, category_id), in <module>
Exception: One or more element ids was not permitted for membership in the assembly instance. Elements should be of a valid category and should not be a member of an existing assembly.
Parameter name: assemblyMemberIds

Try using a loop to check each Id individually instead of all at once. That will at least tell you which items have issues and potentially how to filter/handle them.

What do you mean by this? Those elements definitely have geometry. They would also have a bounding box, so something is going wrong here.

hello @Nick_Boyts I already tried it with a python code that creates an assembly by each element input and output with a list of assemblies created and a list of element IDs that were not able to create assembly, but as you understand this script took like an hour to process for 35000 elements, so I do not see this a method to check if the elements of input can be assembled. this is the code I created for that test:

import clr
from System.Collections.Generic import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
element_array = UnwrapElement(IN[0])
assembly_names = IN[1]

assembly_list = list()
TransactionManager.Instance.ForceCloseTransaction()
# create assemblies
TransactionManager.Instance.EnsureInTransaction(doc)
ids = []
idlist = []
elements_not_allowed_in_assembly = [] # initialize list to store IDs of elements not allowed in assembly

for arr in element_array:
    for elem in arr:
        if elem.Category is not None:
            idlist = List[ElementId]([elem.Id])
            category_id = elem.Category.Id
            assembly_name = assembly_names.pop(0) if assembly_names else "Assembly "+str(len(assembly_list)+1)
    
            try:
                assembly_instance = AssemblyInstance.Create(doc, idlist, category_id)
                TransactionManager.Instance.TransactionTaskDone()
                TransactionManager.Instance.ForceCloseTransaction()
                TransactionManager.Instance.EnsureInTransaction(doc)
        
                assembly_instance.AssemblyTypeName = assembly_name
                assembly_list.append(assembly_instance)
            except Exception as e:
                elements_not_allowed_in_assembly.append(elem.Id)
                pass
    
TransactionManager.Instance.TransactionTaskDone()

OUT = assembly_list, elements_not_allowed_in_assembly

also I filtered those weird elements that do not contain geometry before adding to the input node, which I saw they are the same I found with this script.

but I still get the warning, some assemblies are not created and I do not know why, I do not have idea if the problem are more elements or if it is about the Transactions over a loop.

this is one of the weird MEP elements that I found that they caused problems to create assembly, I found like 16 surprisingly:
Revit_Duct_Modelling_Error

Do you know how those elements were created? That seems like a bug elsewhere that’s now causing issues for the assembly.

I do not know but they are not going to be changed, so I want to know before creating assembly which ones will not work and skip them, so I am asking a way to trace this rubbish because otherwise no assembly can created

That’s where AreElementsValidForAssembly() comes in. You could try creating your assemblies as normal and then add a loop for any group of elements that fails to create. Within that loop, attempt each element individually and filter out those that fail. Then try again with the valid elements.

2 Likes