Index is occupied or out of range

I’ve inherited some legacy python from a previous dev.
Fortunately, they have left a link to the original blog post that was used as a starting point.
But I think I’m hitting a syntax error in the parts they tried to modify.
Specifically at line 96 its saying index is occupied or out of range

IronPython 2.7

#Copyright(c) 2016 
#Please contact at

import clr
import RevitServices
import Revit
import Autodesk
from Autodesk.Revit.DB import *
import math
from math import *


from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

toggle = IN[0]
point = UnwrapElement(IN[1])
modelPoints = UnwrapElement(IN[2])
cropCurves = UnwrapElement(IN[3])
viewType = UnwrapElement(IN[4])

lst = []

#Get Family View Type
vft = 0
collector = FilteredElementCollector(doc).OfClass(ViewFamilyType).ToElements()

#eleViews = []
for i in collector:
	if i.ViewFamily == ViewFamily.Elevation:		
		vft = i.Id
if toggle == True:

		#Retrieve the mid point of model lines and get X,Y.	
	index = 0
	for modelpoint in modelPoints:	
		modelMP = modelpoint.ToXyz()
		modelMPX = modelMP.X
		modelMPY = modelMP.Y
			#Retrieve individual lines of crop window.		
		cropLines = cropCurves[index]
		l1 = cropLines[0].ToRevitType()
		l2 = cropLines[1].ToRevitType()
		l3 = cropLines[2].ToRevitType()
		l4 = cropLines[3].ToRevitType()
			# Create a line in the z-Axis for elevation marker to rotate around.			
		elevationPT = point[index].ToXyz()
		elptRotate = XYZ(elevationPT.X, elevationPT.Y, elevationPT.Z+100)
		ln = Line.CreateBound(elevationPT, elptRotate)
			#Calculate the angle between Model Mid Point and Elevation Point.
		elevationPTY = elevationPT.Y
		elevationPTX = elevationPT.X	
		#combY = elevationPTY-modelMPY
		#combX = elevationPTX-modelMPX	
		combY = modelMPY-elevationPTY
		combX = modelMPX-elevationPTX			
		ang = -atan2(combX, combY)
		comparisonAng = round(degrees(ang))
		newAng = 90
		arrowPos = 2
		eleMarker = ElevationMarker.CreateElevationMarker(doc, viewType.Id, elevationPT, 100)
		#left arrow
		if comparisonAng >= 45 and comparisonAng <= 135:
			arrowPos = 0
			newAng = -90
		#top arrow
		#changed <= to < august 5th 2021
		if comparisonAng <= 45 and comparisonAng > -45:
			arrowPos = 1
			newAng = 0
		#bottom arrow
		if comparisonAng > 135 or comparisonAng < -135:
			arrowPos = 3
			ang = ang + radians(90)
		#default is right arrow
		ele = eleMarker.CreateElevation(doc, doc.ActiveView.Id, arrowPos)
		ElementTransformUtils.RotateElement(doc, eleMarker.Id, ln, ang)
		ElementTransformUtils.RotateElement(doc, eleMarker.Id, ln, radians(newAng))
		#ElementTransformUtils.RotateElement(doc, eleMarker.Id, ln, ang)
			#Create elevation marker and elevation in position 0.
			#Rotate elevation marker towars model line.
		#ElementTransformUtils.RotateElement(doc, eleMarker.Id, ln, math.radians(90))
		crManager = ele.GetCropRegionShapeManager()
			#crShape = crManager.GetCropRegionShape()
		newCurveLoop = []
		cLoop = CurveLoop.Create(newCurveLoop)

			#lst.append("Elevation Created")
			lst.append("Missed Elevation")
		#OUT = degrees(ang)
		OUT = lst

	OUT = "Set toggle to TRUE"

That screen shot is impossible to read, but it looks like this line?

ele = eleMarker.CreateElevation(doc, doc.ActiveView.Id, arrowPos)

That would probably mean that doesn’t exist in the doc structure. I see the object being instantiated, but I don’t see anything which would cause the object to be initialized.

I think you are right, still studying the original blog post to understand where they are setting it at, but management wants another script before I can get back to testing this one. Thanks for the feedback.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.