How to delete family instance if it's listed as a string?

In this script, I’ve narrowed the selection down to a family instance I want to delete. But I can’t figure out how to delete it. As you see here, I can’t hook it up directly to Elements.Delete node, because it’s looking for an element instead of a string.

If I try to use filter by bool mask before hooking up to the delete node, I also get an error, no matter what I connect into the “list” input. In this example, I get the “specified cast is not valid” error.

Do you know what I’m missing? Thanks…

Create a dictionary using the location points as keys and the actual family instances as values. Then, you can retrieve the family instance using the output from your SetDifference node. For example, given 3 FamilyInstance objects and their locations:

instances = [Inst1, Inst2, Inst3]
locations = ['(0, 0, 0)', '(0, 1, 0)', '(0, 2, 0)']

Using locations as keys and instances as values, we would get a dictionary (using Dictionary.ByKeysValues) like this:

{
'(0, 0, 0)': Inst1,
'(0, 1, 0)': Inst2,
'(0, 2, 0)': Inst3
}

NOTE: If multiple elements share the same location, you will have to use a List.GroupByKey node.

If your List.SetDifference node outputs the point '(0, 0, 0)', we can use Dictionary.ValueAtKey node to get the corresponding family instance. In this case, the key is '(0, 0, 0)' and the value would be Inst1, or the actual element.

Great tip! That worked! Thank you very much. I wasn’t aware of that feature.

image