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!
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