Hello @dhilipseshan
you need to get the “cut elevation” CutPlane of the view to set elevation of bounds curve (CropBox)
an example with the active view
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
def createDatumLine(boundLines, grid):
gridLine = None
curveG = grid.Curve
vectGrid = curveG.Direction
ptmid = curveG.Evaluate(0.5, True)
lstPtToLine = []
for lineBound in boundLines:
interResult = lineBound.Project(ptmid)
vectInterResult = Autodesk.Revit.DB.Line.CreateBound( ptmid , interResult.XYZPoint).Direction
if vectInterResult.IsAlmostEqualTo(vectGrid, 0.1) or vectInterResult.IsAlmostEqualTo(vectGrid.Negate(), 0.1):
lstPtToLine.append(interResult.XYZPoint)
if len(lstPtToLine) == 2:
gridLine = Autodesk.Revit.DB.Line.CreateBound(lstPtToLine[0], lstPtToLine[1])
return gridLine
def getBoundLines(bbx, Zvalue ):
lstPt = []
lstLine = []
lstPt.append(XYZ(bbx.Min.X, bbx.Min.Y, Zvalue))
lstPt.append(XYZ(bbx.Max.X, bbx.Min.Y, Zvalue))
lstPt.append(XYZ(bbx.Max.X, bbx.Max.Y, Zvalue))
lstPt.append(XYZ(bbx.Min.X, bbx.Max.Y, Zvalue))
for idx, pt in enumerate(lstPt):
if idx == 0:
lstLine.append(Line.CreateBound(lstPt[- 1], pt))
else:
lstLine.append(Line.CreateBound(lstPt[idx - 1], pt))
return lstLine
activView = doc.ActiveView
cropBox = activView.CropBox
viewRange = activView.GetViewRange()
cutOffset = viewRange.GetOffset(PlanViewPlane.CutPlane)
fecGrids = FilteredElementCollector(doc, activView.Id).OfClass(DatumPlane).ToElements()
outLst = []
boundLines = getBoundLines(cropBox, cutOffset)
TransactionManager.Instance.EnsureInTransaction(doc)
for grid in fecGrids:
newGLine = createDatumLine(boundLines, grid)
if newGLine:
grid.SetCurveInView(DatumExtentType.ViewSpecific, activView, newGLine)
outLst.append(newGLine)
TransactionManager.Instance.TransactionTaskDone()
OUT = outLst