I want to use GetItemAtIndex for one list, but I need to keep the order of the list, although the first four values can not be find in the list. I just want to have an empty or blank value, instead of null. Everything in my script works like this, I just want to get rid of the warnings. Is there any way I can avoid the warnings when using GetItemAtIndex which can not be found in the list?
Thanks!
I would be interest to see how you arrive at this point since I typically use GetItemAtIndex paired with List.AllIndicesOf, this doesnt return any blank values. Example below which may and probably not useful to your workflow
For this I always use a Python loop containing an if-statement that checks if the value is -1, if so it then appends an empty list. If that is not the case it gets the index of that item and append it.
I also tried to do this with DesignScript but that only returns a single empty list instead of multiple.
my_list = IN[0]
my_indices = IN[1]
def get_sublist(lst, indices):
sublist = []
for index in indices:
if index == -1:
sublist.append([])
else:
sublist.append(lst[index])
return sublist
OUT = get_sublist(my_list,my_indices)
You don’t have matching list lengths. You’ll have to deal with this first. Based on the error you’re getting with python, you may have to convert your indices to integers as well.
That’s fine. I’m just saying that’s may be why the If statement won’t work for you. If you require different list lengths then you can always use another solution like python. In which case you need to address the error it’s giving you.