I am trying to get this script to work better for setting the gridlines to the crop region of a view. currently this will work pretty flawlessly when you are on the first floor of a building. Once you go to the second, third and so on it is just giving errors within the python script. I do not know enough about python to figure out what is happening here.
Is there anyone that would be able to take a look at this script and the Python script to see what could be causing this? Within the python line 62-63 - viewRange = activView.GetViewRange()
cutOffset = viewRange.GetOffset(PlanViewPlane.CutPlane)
i am wondering if this might have something to do with it.
import clr
clr.AddReference('ProtoGeometry')
import Autodesk.DesignScript.Geometry as DSGeo
from Autodesk.DesignScript.Geometry import *
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
def createDatumLine(boundLines, grid):
gridLine = None
curveG = grid.Curve.ToProtoType()
vectGrid = curveG.Direction
ptmid = curveG.PointAtParameter(0.5)
lstPtToLine = []
for lineBound in boundLines:
lineBoundDs = lineBound.ToProtoType()
ptmid = DSGeo.Point.ByCoordinates(ptmid.X, ptmid.Y, lineBoundDs.StartPoint.Z)
interResultA = ptmid.Project(lineBoundDs, vectGrid)
interResultB = ptmid.Project(lineBoundDs, vectGrid.Reverse())
if len(interResultA) > 0:
lstPtToLine.append(interResultA[0].ToXyz())
if len(interResultB) > 0:
lstPtToLine.append(interResultB[0].ToXyz())
if len(lstPtToLine) == 2:
gridLine = Autodesk.Revit.DB.Line.CreateBound(lstPtToLine[0], lstPtToLine[1])
return gridLine
def getBoundLines(bbx, Zvalue = 0):
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
thank you in advance for any and all help