Arguments invalid in index of

Hello, as far as I know this should work, but Ive tried everything and I cannont find the index number of these elements in this list. What am I doing wrong it says my argument is invalid weather or not I use strings??

I believe you want @1 for telement, not list. The node is currently looking for a list at level 1, but level 1 will always be a singleton.

Like this?

No list levels for the list input. I think it will check each level by default.

Edit: You should be using the IndexOf node from DanEDU.

ok now we are making progress, but how do I get elements at these indicies? There is no get element at index that works with indicies in this format is there?

Oddly enough I don’t think there is. Hey @erfajo, I know you have a ReplaceItems node but do you have any plans to make a GetItems node as well?

What you’ll have to do in the meantime, @mix, is write a quick python script that would get items from a list using this format. (I assume that’s what Erik would do for a custom node anyway.)

Thats a good Idea, but no can do, I havent learned python yet. Its on my to-do list. but by to-do list is very loooong. :frowning:

Right, we use IndexOf to get the nD indices of an item, but now if you want to get items from another list at those indices (not replace them) what do you do? I’m looking for something like GetItemAtIndex.

I hope you don’t mind but I have been going through the forums looking for Dynamo/Python practice and took a shot at making a python script to get items using your list of indices format:

elems = IN[0]
indices = IN[1]


def recGet(ele,ind,out):
	temp = list(ind)
	if len(temp)>1:
	  recGet(ele[temp.pop(0)],temp,out)
	else:
	  out.append(ele[temp[0]])

outlist = []

for i in indices:
	recGet(elems,i,outlist)
	
OUT = outlist

I believe it works but I don’t know what the best format for output would be, if keeping the structure is important, then this would be it:
listindex2_danedu

elems = IN[0]
indices = IN[1]


def recGet(ele,ind,out):
	temp = list(ind)
	tempL = []
	if len(temp)>1:
	  recGet(ele[temp.pop(0)],temp,tempL)
	  out.append(tempL)
	else:
	  out.append(ele[temp[0]])

outlist = []

for i in indices:
	recGet(elems,i,outlist)
	
OUT = outlist
2 Likes

Nice. I would think you would want to keep list structure, but maybe you could add a toggle as an option?

Neither of these scripts appear to work:




That is because for some reason your index lists are within a nested list at level 2, as seen in the picture where IN[1] comes from, the output is a 0 list, 0 list, then the indices. Try feeding that node through a flatten by n node, where the amt is 1. See below:

Edit: Alternatively, you could replace the python node with this script:

elems = IN[0]
indices = IN[1]


def recGet(ele,ind,out):
	temp = list(ind)
	if len(temp)>1:
	  recGet(ele[temp.pop(0)],temp,out)
	else:
	  out.append(ele[temp[0]])

outlist = []

for i in indices:
	recGet(elems,i[0],outlist)
	
OUT = outlist

I cant seem to get this node to work as indicated. Please advise.

Wait, it appears i found the magic list level structure, however, how do I keep the elements in their original sublist? My parent list has 3 groups, I want to find and group the elements in those groups with out losing the groups. So I should have 3 lists of 8 elements each. RN its finding 24 lists of 1 element each.

1 Like

You mean like this? This way it doesnt work at all. :confused:

@erfajo
Sure, im sorry, I know I dont have the most organized graphs. Ill try to explain it better here.
these nodes appear to take the element types that I am feeding them just fine. The only problem is that it is not grouping the elements into their proper repective subgroups like your example post did. I want that. But this is what is happening:

However, if I turn off levels like you suggest. They dont work at all.

Are you suggesting that this is better, or am I doing something wrong?
Thanks

For once I think I finally solved my own problem. I used Group by function node to do it. I grouped all the lines by their initial index which appears to be consistently the number of the sublist group the element belongs to. I have yet to test this but it is finally in the format I was after. I didnt think of this before because I still dont understand the Groupbykey or Groupbyfunction nodes (so if anyone has more documentation than what is in the dynamo dictionary on these nodes please send it my way!) but I managed to hack my way through it in a way that made sense in my brain. Here is what it looks like, please comment if you see an error in my logic. Thanks!

2 Likes