I was wondering what is the best method to check if an instnace of a family exist at a particular location, before placing one?
I was thinking I could create a list of all the instance of that element, check to see if any of them has same placement point, and if yes, skip, if not place an istance at that point.
is there a better way to do this?
Depends on your use case. Is this placement point just an arbitrary coordinate?
I made a tool that places seismic brace families on rods of fabrication hangers, and I write the uniqueId of the braces to the hanger. Then if I try and place additional braces on the same hanger it checks for the element with that id and if it exists it skips it. If it does not exist anymore because it was deleted then it places a new brace and updates the uniqueId.
Hi,
The purpose of my script is to find where pipes / ducts etc clashing with walls, find the centre point of the clash, and place a family that represents builders work opening at that point. The family is a generic model family
Since you are placing a single family it could make sense to check all that have been placed. Here is something that I have done. It is not the best way but it does work.
def check_for_existing_instance(family_symbol, insertion_point, tolerance=0.000001):
family_instance_filter = DB.FamilyInstanceFilter(doc, family_symbol.Id)
# Use the filter to get instances of the specified family symbol
existing_instances = DB.FilteredElementCollector(doc).WherePasses(family_instance_filter).ToElements()
# Check if there are any instances close to the insertion_point
for existing_instance in existing_instances:
if insertion_point.DistanceTo(existing_instance.Location.Point) < tolerance:
return existing_instance
return None
Alternatively, you can also place the element and check to see if Revit tells you that there are duplicates and then undo the transaction.
If you want to be able to track the placements noted by @jpitts you could add the GUID of the placed family to a parameter on the pipe/duct. Also not a bad way to go.
I have created similar scripts in the past and also found it helpful to add a yes/no parameter for managed by script in case a user manually places that family. That way you can distinguish between automated and user placements.
and thanks for your reply
your first suggestion, is exactly the approch I have used.
But I was thinking this could be process heavy on a big model (I could be wrong, don’t know much about programming), so was asking if there was a better way of doing this
Thanks again for your help