DSCore.List.RemoveItemAtIndex() error

i have this warning when using RemoveItaemAtIndex Function in Python:

image

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('DSCoreNodes')
import DSCore
from DSCore.List import *

import System
import sys
pyt_path= r"c:\program Files (x86)\ironPython 2.7\lib"
sys.path.append(pyt_path)

import math

pts = [0,1,2,3,4,5]

OUT = DSCore.List.RemoveItemAtIndex(pts,0)
2 Likes

The actual command of RemoveItemAtIndex only works with a single index. Nodes can be built to accept lists as it treats each item in the list as a separate RemoveItemAtIndex command, but in Python, it will not do that automatically. You will have to create a for loop. There are better ways to do this in python though.

1 Like
def tolist(obj1):
	if hasattr(obj1,'__iter__'): return obj1
	return [obj1]

def removeindex(elements, index):
	ran = range(0,len(elements))
	lst = []
	for e, r in zip (elements, ran):
		if r not in index:
			lst.append(e)
	return lst


elements = tolist(IN[0])
index = tolist(IN[1])

rev = removeindex(elements, index)			

OUT = rev

1 Like

Hello @zminoo76 and welcome ! :grinning:

thanks for sharing

Please avoid to digging up an old topic
forum rules and guidelines