List Get at index in depth [4] vs [3]

I’m looking to map information from a dataframe, in Revit 2020, as CPython3 is not available, I can’t use pandas so I have to do it old-school

The objective is to obtain the indices of a list with depth 4, (List of Elements by category with List of Parameters with Sublist Values) vs List of Elements of category with List of Elements) .

The detail is that the mapping is done by brute force and I cannot unstructured the list to reduce the complexity, so although some elements are not contained within the list of the parameters I have to pass it to avoid a value placement error.

The clearest example would be seen here, I have to pass the empty lists of elements within the comments list, and then continue through list two that if it has elements.

# The inputs to this node will be stored as a list in the IN variables.
IndexVals = IN[0]
TLFParN = IN[1]
ListVal = []
# Place your code below this line
for LSval in TLFParN:
	templist = []
	for LVal,indices in zip(LSval,IndexVals):
		tempsublist = []
		try:
			for i in indices:
				value = LSval[i]
				tempsublist.append(value)
			templist.append(tempsublist)
	ListVal.append(templist)
# Assign your output to the OUT variable.
OUT = ListVal

Here I left one script with the example prExample-Question.dyn (10.6 KB)
oposed

What kind of database are you talking about?
SQL or otherwise?

1 Like

It is a spreadsheet with different sheets of schedules. Those schedules have quantities from link models for that, Now I try to find the elements in the current model ( The result is the index), and then I want to access the value on the excel to set in the model; that’s why I have this deepness in the lists.

Hi @Luiscko,

I read your case, but I cannot figure out what you are trying to do here. I have checked your example file and this too doesn’t make it clear. What are you trying to do with these 2 array’s in the example file?

you first list is a list containing “List of Elements by category with List of Parameters”?
000193

your second list contains what, Indices of some sort?
000194

Could you some how show what the end result should be or explain it a bit more?

1 Like

Sure
The result for this case will be:

List
 List 0
	List 0
		0 Empty List

	List 1
		0 Val1
		1 Val5
	List 2
		0 Temp1
		1 Temp1	
 List 1
	List 0
		0 Empty List

	List 1
		0 Temp1
		1 Temp5
	List 2
		0 Ejem01
		1 Ejem04

@Luiscko

Hi,

You can try this:

# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# The inputs to this node will be stored as a list in the IN variables.
IndexVals = IN[0]
TLFParN = IN[1]

# Place your code below this line
ListVal = []
for LSval in TLFParN:
    templist = []
    for Lval, indexes in zip(LSval,IndexVals):
        if indexes == []:
            Lval = []
        else:
            for i in indexes:
                Lval[i] = i
        templist.append(Lval)
    ListVal.append(templist)
    
# Assign your output to the OUT variable.
OUT = ListVal

Regards,

1 Like

Thank you very much but It give more outputs that suppose to deliver.

Carlos from BIM Central Mexico resolved this problem with this code.

# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# The inputs to this node will be stored as a list in the IN variables.
IndexVals = IN[0]
TLFParN = IN[1]

# Place your code below this line
ListVal = []

def findMySet(lsSet, indexVals):
	lsData = []
	m= 0
	for IsIndexes in indexVals:
		data = []
		if len(IsIndexes) > 0:
			for indx in IsIndexes:
				if len(lsSet[m]) >= indx:
					val = lsSet[m][indx]
					data.Add(val)
		m += 1
		lsData.Add(data)
	return lsData		

for lsSet in TLFParN:
	resVal = findMySet(lsSet,IndexVals)
	ListVal.Add(resVal)

    
# Assign your output
OUT = ListVal

See if this also works for you …

def getNstdIndx (lst:var[]..[],ind:var[]..[])
{
	return List.GetItemAtIndex(lst<1>,ind<1>);
};
getNstdIndx (lst<1>,ind);
5 Likes

This other level, a terrific way to solve it in a few lines of commands :scream: :ok_hand:

1 Like

Push the limits. :smiley:

# The inputs to this node will be stored as a list in the IN variables.
IndexList = IN[0]
ValueList = IN[1]

# Place your code below this line.
OutValues = [[[] if index == [] else [valList[i][item] for item in index] for i, index in enumerate(IndexList)] for valList in ValueList]
# Assign your output to the OUT variable.
OUT = OutValues

6 Likes

A one liner :stuck_out_tongue_winking_eye:

List.GetItemAtIndex(a<1><2>,List.OfRepeatedItem(b,List.Count(a))<1><2>);

6 Likes

The Wizard of Bangalore at it again

2 Likes

I couldn’t resist the temptation :upside_down_face:

indexList = IN[0]
valueList = IN[1]

OUT = [[map(vals.__getitem__, ind) for ind, vals in zip(indexList, lstitems)] for lstitems in valueList]
6 Likes