Script not working on multi floor project

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
import Autodesk.DesignScript.Geometry as DSGeo
from Autodesk.DesignScript.Geometry import *

#import Revit API
import Autodesk
from Autodesk.Revit.DB import *

#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

import Revit

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:
        if len(interResultB) > 0:

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

for grid in fecGrids:
    newGLine = createDatumLine(boundLines, grid)

    if newGLine:
        grid.SetCurveInView(DatumExtentType.ViewSpecific, activView, newGLine)


OUT = outLst

thank you in advance for any and all help

Are force rerunning the graph each time? Ether by using force rerun, closing and opening it, or changing your t/f on the active view node?

Also, what is the error?

So for this given project i have a ton of segment views and i will run this for each of the segment views. when i am working on the first floor views it seems to work fine but not on the others.

Normally i would just use the Dynamo player and i will hit the play button for each view.

i leave everything open, and for the boolean i normally leave that on false.

Try closing the graph after each run and let me know. Where did you get the python script?

At a quick glance, I cannot find where it is operating on any of your inputs.

this is all from something that i found on the internet. even closing it and then reopening dynamo it doesnt seem to make a difference. i know that it is never good to do that but within a post i saw that this worked for them so i opened up dynamo and started to build it off the images that were uploaded.