Arguments invalid in index of


#1

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


#2

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.


#3

Like this?


#4

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.


#5

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?


#6

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


#7

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:


#8

Yes, it is called IndexOf, and was made app. two hours before ReplaceItems :slight_smile:

first i made a node that could find items in nD lists… then I had to use that for something, so i made replaceItems (in nd lists) :slight_smile:

List Index (2 nodes).dyn (10.6 KB)


How to replace all null with multiple values
#9

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.


#10

aha… like that.
I will put it on my todo list :slight_smile:

I think I will go for a C# script just to practice that :slight_smile:


#11

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

#12

@kennyb6, good job :slight_smile:

I like to share, so take whatever you like and tweak it as you please :slight_smile:


#13

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


#14

thats a good idea… but as you know, am i investigating C# at the moment, so I would give that a try. However, I have also a project at the university, where we want to improve a method for fire protection calculation, which I have to se how I can contribute to. So i am nearly overloaded by project at the moment :slight_smile:


#15

Neither of these scripts appear to work:





#16

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


#17

I took a break from my other duties and used half an hour coding a node that could be used with the other nodes. The update is released as 2018.0301.3

@kennyb6 methods work perfect, but in the data structure, he has set. My new GetItemAtIndex follows the data structure used in my package.

List Index (3 nodes).dyn (13.7 KB)


#18

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


#19

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.


#21

my nodes works recursively, which means that levels should not be used.
It will return the structure you put in. in other words, when you tweak the input using list level, then it will influence on the output.