How to retrieve information from a python block


#1

Hi,

I have a small concern about making a Python node.
I can not get the list out of the program. I obtain only an “Empty List”…

However, this is very simple block of code, it intended to create a list from the conditions imposed by two separate lists.

Code Below :

#2018/01/03
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import méthode extension
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

#Entry
A = IN [0]
B = IN [1]
C = IN [2]

#Definition
i=0
j=0
x=0
imax=len(A)
jmax=len(C)

l = []

#Creation
for j in range(jmax):
    for i in range(imax):
        if C[j]==A[i]:
            C[j]=B[j]
            break

#Exit
OUT = l

Thank you !

A French guy


#2

Hi @Blond,

I can’t quite figure out what you are trying to do, but your output in an empty list (l).

The values you want out of the python script, you need to append to the outlist, by using the append() method.

Good luck :slight_smile:


#3

Hi martin,

thank you for your reply.

I tested with the append method and I get to the same problem.

I have the impression that the list (l) is not modified…
May be an computer reason (pointer) ?

:

Sacrebleu


#4

Can you post your dyn file so we don’t have to recreate the code?


#5

I try but it seem impossible for new user on this forum.

Sorry


#6

ah. Can you post them to a dropbox, google drive, or other file share service? Even if you could just post the formatted python code (use the </> button in the toolbar of the reply composition box) it helps us help you. :slight_smile:


#7

Okay !
No problem

Python Code below :

#2018/01/03
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import méthode extension
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

#Entry 
A = IN [0]
B = IN [1]
C = IN [2]


i=0
j=0
imax=len(A)
jmax=len(C)


l = []

for j in range(jmax):
    for i in range(imax):
        if C[j]==A[i]:
            C[j]=B[j]
            break

#Exit
OUT = l

#8

@Blond
Just write there what is result list you want to see?


#9

In this case, I’d like to get a list containing {30,30,30,30}.
And no an empty list.

The fact that the OUT doesn’t return anything is a mystery for me…


#11
lst=[]
for i in zip(IN[0],IN[1]):
	for x in IN[2]:
		if i[0]==x:
			lst.append(i[1])	

OUT=lst

#12

or this… essentially the same, but more elaborated.

A_list = IN[0]
B_list = IN[1]
C_list = IN[2]

t = []
for a_item, b_item in zip(A_list, B_list):
    for c_item in C_list:
        if a_item == c_item:
            t.append(b_item)
OUT = t

another method

A_list = IN[0]
B_list = IN[1]
C_list = IN[2]

t = []
for idx, a_item in enumerate(A_list):
    for c_item in C_list:
        if a_item == c_item:
            t.append(B_list[idx])
OUT = t

#13

Awesome. Thank you.