How to get the position(location) of the component in the grid with dynamo revit?

How to get the position(location) of the component in the grid with dynamo revit? Thank you very much!!
how to get the elements grid location with dyanmo_revit2019.rvt (3.1 MB)


How to get the grid location of these column elements with dynamo?
Such the first column element is near the grid “1-2/A-B”
Like the parameter of grid location from the navisworks crash report!

Could you be more specific here. Do you mean you need the closest grid to elements?

1 Like

:grinning:
Yes, you are right!

Could you share rvt file and let us know which elements you’re trying to find?

1 Like

OK,i will

I have uploaded the file! Thanks a lot!

Hi!

I have been working recently on a similar issue - it is a bit different as it looks for grid intersections rather than for 4 surrounding grids…but maybe it will be useful for you:

import clr,math
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
#The inputs to this node will be stored as a list in the IN variables.
points = UnwrapElement(IN[0])
grids = UnwrapElement(IN[1])

def distance2d(a,b):
	return math.sqrt((b.X-a.X)**2 + (b.Y-a.Y)**2)

intersections = []

for g0 in grids:
	for g1 in grids:
		if g0!=g1:
			resultArray = clr.Reference[IntersectionResultArray]()
			result = g0.Curve.Intersect(g1.Curve,resultArray)
			if result==SetComparisonResult.Overlap:
				intersections.append([resultArray.Item[0].XYZPoint,g0.Name,g1.Name])
			
closestIntersections = []

for p in points:
	intersections.sort(key=lambda x:distance2d(p,x[0]))
	closestIntersections.append(intersections[0])

#Assign your output to the OUT variable.
OUT = closestIntersections

What this code does it takes as an input points and grids and then for each point it finds a closest grid intersection. The output is a list of sublists - one sublist per point. Each sublist contains three elements - intersection point, 1st grid name, 2nd grid name.

Also note that you might run into units issue as Dynamo units can be different than Revit internal. Therefore I use another Python node to get locations in internal units (you might not need this):

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
#The inputs to this node will be stored as a list in the IN variables.
elements = UnwrapElement(IN[0])
locations = []

for e in elements:
	locations.append(e.Location.Point)

#Assign your output to the OUT variable.
OUT = locations
3 Likes

Amazing! Thanks for sharing the python scrip! I will try it later。

Try this script as other way away of python if you are not interesting in.
Nearest axes.dyn (72.7 KB)