How is the best way to get the elements location of any family type with python?

How is the best way to get the elements location of any family type with python in Dynamo for Revit? Some elements location is a point, line, sketch lines…

@ruben.romero ,

# Phython-Standard- und DesignScript-Bibliotheken laden
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Die Eingaben für diesen Block werden in Form einer Liste in den IN-Variablen gespeichert.
elems = IN[0]

output = []

for i in elems:
    output.append(i.Location)

OUT = output

i tried with category…

you could also run it in a 3D view all categories activated…

or combineing collectors

1 Like

The best way would be to have a condition for each location method and to use the element’s category to determine which method gets used.

The easier way would be to use a couple try statements for each of the location methods.

2 Likes

You’re right! A good approach is to check each element for specific attributes that represent their location, such as “Coord”, “Curve”, or “Location”. By doing so, we can handle different types of elements and their respective location properties, ensuring that we retrieve the correct location information for each element in the model. For example:

def GetLocation(item):
if hasattr(item, “Coord”):
return item.Coord
elif hasattr(item, “Location”) and item.Location.ToString() == ‘Autodesk.Revit.DB.LocationCurve’:
return item.Location.Curve
# … and so on for other location attributes

This function checks each element for different location attributes and returns the appropriate location information, allowing us to accommodate various element types.

1 Like
def GetLocation(item):
    if hasattr(item, "Coord"):
        return item.Coord
    elif hasattr(item, "Location") and item.Location.ToString() == 'Autodesk.Revit.DB.LocationCurve':
        return item.Location.Curve
# … and so on for other location attributes
2 Likes

Hi @luisaECXV3 how about clockwork get location but not sure

1 Like

Just to be clear, Location is and element class property. You can use it to get the location of just about any instance. The only thing you need to deal with is how to utilize that location afterwards since it can be different geometry types.

It might be helpful if you gave us more information on what you’re actually wanting to do.

1 Like

I understand your point of view, and I would like to add that sometimes we encounter situations where we require a single point for each object, which leads to the need for custom functions. However, I find Clockwork to be a reliable point of reference in such situations, especially with its Location+ node. I hope this perspective aligns with your own.

Thank you! I am new here and don’t know how to use the code box :slight_smile:

Check out element.location+ in clockwork.

Often i prefer to get the bounding box of element then get the point at UVW 0.5,0.5,0. Not perfect but a good general approach.

2 Likes

Bounding box is handy and quick but I can’t believe the weird results of Bounding box of elements can appear, for example some families appear with a massive Bounding box wrapping until the origin point of the project instead to be around the geometry, i am not sure if that was MEP family or structural connections elements, so goodbye Bounding box i don’t believe on it.

I reused part of the python code of clockwork location +, simplified and added conditions to get one single output geometry location by element input.

1 Like

Bounding boxes are generally correct. The way people model is not, and is the culrprit in those cases i suspect.

4 Likes