Filter list by another list

Hey guys,

I have a list of families (took from a parent folder, including a subfolder).
My wish is to ONLY import families to a project that are containing the names shown on the left list.
This list comes from an excel file.

How can I do this? Must be something easy, but I’m missing it somehow.

Thanks

So you have already done the filtering I see. You can use a custom node or a little python script to import all the Families using their File Paths. Python script below:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('System')
clr.AddReference("System.IO")
from System import *
from System.Collections.Generic import *
from System.IO import *
#Use elemIds = List[ElementId](ids) for ICollection(ElementId)

#Import the Revit Services
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#Import the Revit API
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *


def tolist(obj1):
	if hasattr(obj1,"__iter__"):
		return obj1
	else:
		return [obj1]
		
#Define Input (IN)
filepaths = tolist(IN[0])
output = []

# Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

for filepath in filepaths:
	succes = doc.LoadFamily(filepath)
	output.append(succes)
	
#End Transaction
TransactionManager.Instance.TransactionTaskDone()

#Define Output (OUT)
OUT = output

Let me know if this works for you

1 Like

If you don’t want to type, you can do this with OOTB nodes as well:

1 Like

@infeeeee

Nodes looked easier so I tried that first. But it ain’t working.
Am I doing something wrong? It should show the 6 items shown in the left list. But it shows a random one?

Thanks for your comment @Joelmick. Is it true the script does only the “loading” and not the filtering?
Clockwork has a node for only the loading-part called: Document.LoadFamily:

Screenshot_4

What I need is to filter the right list (shows every family) by the left list.(what I need).

I thought you already had the filtering done. Yes the Node from clockwork works the same way. A nice feature there is that is also returns the Families.

The ways @infeeeee showed is indeed the best and simplest way to filter!

1 Like

Yes he filtering is done, but isn’t applied on the load-family node. I don’t want to load all the families in that path.
Now I only need to make that script work from @infeeeee :roll_eyes:

Take a better look at the example posted, he is using List at Level to get the functions to work with the nested lists.

2 Likes

You mean this @Bjorn_Keulemans1 ?
Screenshot_5

I have no clue how to do that :grimacing:. Thought it was an adittional thing.

https://primer.dynamobim.org/06_Designing-with-Lists/6-3_lists-of-lists.html

List@Level halfway down on the page.

1 Like

Mind blown. Found out it was just the arrow (lol). But it doesn’t change the outcome though:

Again, take a better look at the example. You’re switching on the List@Level on the wrong nodes.

Read the primer, learn why you are doing this.

I get your point @Bjorn_Keulemans1 and I understand the example. Especially this image making everything more clear:

But my script still doesn’t do what I want. I saw the mistake I made and corrected it, but there is something i’m missing, because it doesn’t filter…

Even playing stupid and randomly changing the list@level nrs won’t give the proper results. I don’t even understand the results it’s giving: looks so random?

Hoi

This is something String.contains if you have a name in a name, in this example “Kim kopschot” does also exist in Kim kopschot UNP…
You need a other selection method. Do not ask me how.

Groeten Jan-Willem

1 Like

Thanks for your comment Jan-Willem. The “kim kopschot unp” should be the only one not active in the end-list, but it won’t happen. Your observation with overlapping names sounds logic. Too bad you don’t have a solution for it :smile:

Got it! I added .rfa to the first list and it’s working now. Your comment gave me a right push @jwroelofs!

Screenshot_8

Another way would have been to add the folder path in front and the .rfa suffix to the original string. Then there is no need for any filtering.

That’s how I had it, but having subdirectories gave a problem adding the folder path in front of it. How would you solve it?

My library has (almost) no subfolders anymore. Once your family filenames are set up according to a (national) standard, they will usually include a Code and a Category abbreviation. So sorting or searching in explorer is a quicker way than having 100+ subfolders in your library.

That’s not even going into detail of various library managment tools.

In short, this is not a problem I would tackle on the Dynamo side of the organisation.

Thanks for your feedback. What you say is true, but not applicable for our situation.
Also keep in mind other dynamo users still can learn from this process :slight_smile:

1 Like