Help with Python

Hi All,

I’m quite new in Python, and for the issue I need, there are some things I don’t know how to script them.

For the multi-story wall above, I managed to get the segments of the curves that define the walls (INPUT: GetLocation), recognising the edges of the upper and lower wall.

TASK: I want to check if a segment of the wall in the “i” story exist in the “i+1” story.

To do that, I want to check every segment of the “i” story and compare its Curve.StartPoint and the Curve.EndPoint (X,Y) coordinates to the minimum and the maximum (X,Y) points from the “i+1” and “i-1” story (see green reclangle - I have this as an INPUT for the python node, but this can be created inside the python script).

I want to to this for vertical reinforcement, so the are quite different posibilities for a segment:

  • The “i” story segment is contained by a wall in the “i+1” and “i-1” story.
  • The “i” story segment is contained only by a wall in the “i+1” or “i-1” story.
  • The segment Curve.StartPoint (X,Y) is the same of the Minimum or Maximum for the “i+1” or “i-1” (X,Y) story. The same for segment Curve.EndPoint.

The GOAL here is to tag with some “identificator” (can be a string) the different cases, but always arranged by story.

My Python limitations are that I don’t know how to access levels of the sub-lists and compare them to the Min and Max.

The first python code is:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

#Entradas para las coordenadas (X,Y) de los puntos inicial y final de las curvas que crean los muros.

#Start Point
x1 = IN[0]
y1 = IN[1]

#End Point
x2 = IN[2]
y2 = IN[3]

cuenta = x1.Count

i=0
k=1

resultado_actual = []
actual = []

for i in range(cuenta-1):
# Almacena las diferencias para el piso actual

#Corrdenada X
	dif_xi = x1[i+1] - x1[i] 
	dif_xj = x2[i+1] - x2[i]  

	if dif_xi > 0:
		dif_xi = dif_xi
	else:
		dif_xi = 0
	
	if dif_xj < 0:
		dif_xj=dif_xj
	else:
		dif_xj = 0
			
	actual_x = [x1[i]+dif_xi, x2[i]+dif_xj]

#Coordenada Y	
	dif_yi = y1[i+1] - y1[i] 
	dif_yj = y2[i+1] - y2[i]  
	
	if dif_yi > 0:
		dif_yi = dif_yi
	else:
		dif_yi = 0
		
	if dif_yj < 0:
		dif_yj=dif_yj
	else:
		dif_yj = 0
		
	actual_y = [y1[i]+dif_yi, y2[i]+dif_yj]
		
	actual = [actual_x, actual_y]
	
	resultado_actual.append(actual)
	
OUT = resultado_actual

Here is a shot of the script:

I hope my explanation was clear enough.

Hope if you could help me with this or give me some directions.

Thanks in advance for the time!

Cheers!

PS: [quote=“Jorge_Villarroel, post:1, topic:13114”]
The GOAL here is to tag with some “identificator” (can be a string) the different cases, but always arranged by story.
[/quote]

When I say “Tag” I don’t mean, element/wall tag. Just an indicator for scripting purposes.

I made a simplier example:

Here is my lack of knowledge in python:

  • How can I access a sublist?
  • Why is this error happening “List is not callable”?

Here’s my code:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *

#Entradas para las coordenadas (X,Y) de los puntos inicial y final de las curvas que crean los muros.

#Start Point
segs = IN[0]		#segmentos por piso
minimo = IN[1]		#minimo del piso superior
maximo = IN[2]		#maximo del piso superior
aux = []

i=0
for i in segs:
	for s in segs(i):
		if segs(i)(s) == minimo:
			aux.append("Min")
		else:
			pass
	i=i+1
	
j=0
for i in segs:
	for k in segs(j):
		if segs(j)(k) == maximo:
			aux.append("Max")
		else:
			pass
	j=j+1

OUT = aux

Thanks

Got it done for the simple example… I’ll try for the robust example.

   import clr
    clr.AddReference('ProtoGeometry')
    from Autodesk.DesignScript.Geometry import *

    clr.AddReference('DSCoreNodes')
    import DSCore
    from DSCore import *

    #Entradas para las coordenadas (X,Y) de los puntos inicial y final de las curvas que crean los muros.

    segs = IN[0]		#segmentos por piso

    #Calcula el mínimo y el máximo de cada piso.
    aux_minimo = []
    for i in segs:
    	aux_minimo.append(min(i))		

    aux_maximo = []
    for i in segs:
    	aux_maximo.append(max(i))	

    minimo = min(aux_minimo)
    maximo = max(aux_maximo)

    i=0
    j=0

    resultado = []

    #Chequea si los 
    for i in range(0,len(segs)):
    	aux = []
    	for j in range(0,len(segs[i])):
    		if segs[i][j] == minimo:
    			aux.append('Min')
    		elif segs[i][j] == maximo:
    			aux.append('Max')
    		else:
    			aux.append(segs[i][j])
    	resultado.append(aux)

    OUT = resultado