Getting Grid Lines Geometry aligned to the Section View

Hi Dynamo Buddies,

I am working on automatic dimensioning of elements to the nearest grid. However, I am able to find the grid curve closest to the element in the plan when I am trying to create auto dimensioning in Section views , I am noticing that the grid curve geometry is parallel to the plan and not parallel or aligned to the section view, so difficulty in finding the nearest grids by distance.

so is there any way where I can get the grid curve parallel to the section view?


Thanks in Advance.

You can find it after getting intersect line between grid and the section first.

@Hyunu_Kim I got it from bounding box aligned to view

import clr

import sys

import System
from System.Collections.Generic import *

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")

import Autodesk 
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication 
app = uiapp.Application 
uidoc = uiapp.ActiveUIDocument

def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

# Grouping Parallel lines Function
def groupparallellines(lines):
	Groups, Queue = [], []
	while lines:
		group = []
		Queue.append(lines.pop())
		while Queue:
			l1 = Queue.pop()
			group.append(l1)
			for i in range(len(lines)-1,-1,-1):
				if l1.Direction.IsAlmostEqualTo(lines[i].Direction) or l1.Direction.IsAlmostEqualTo(lines[i].Direction.Negate()):
					Queue.append(lines.pop(i))
		Groups.append(group)
	return Groups

#change revit bounding box to 2d rectangle in the plane present
def boundingboxto2drectangle(bbox):
	a=bbox.Min
	b=bbox.Max
	p1=XYZ(a.X,a.Y,a.Z)
	p2=XYZ(b.X,a.Y,a.Z)
	p3=XYZ(b.X,b.Y,b.Z)
	p4=XYZ(a.X,b.Y,b.Z)
	l1=Line.CreateBound(p1,p2)
	l2=Line.CreateBound(p2,p3)
	l3=Line.CreateBound(p3,p4)
	l4=Line.CreateBound(p4,p1)
	del a,b,p1,p2,p3,p4
	return [l1,l2,l3,l4]
	
#get the revit rectangle list lines to get the centre line
def rectanglecentreline(recs):
	recs=groupparallellines(recs)
	l1=Line.CreateBound(recs[0][0].Evaluate(0.5,True),recs[0][1].Evaluate(0.5,True))
	l2=Line.CreateBound(recs[1][0].Evaluate(0.5,True),recs[1][1].Evaluate(0.5,True))
	if l1.Length>=l2.Length:
		return l1
	else:
		return l2

#getting the grid curve aligned to current view
def getgridcurveinview(grd,viw):
	bbx=grd.get_BoundingBox(viw)
	bb2d=boundingboxto2drectangle(bbx)
	l=rectanglecentreline(bb2d)
	del bbx,bb2d
	return l
1 Like