How can I iterate a geometry process with Python? (Create a diagonalized polygon from the lenght of its segments)

Hello everyone

I’m trying to generate a diagonalized polygon from its structure, created with model lines within a Revit model, and distances, introduced by user through Excel.

And, thanks to this forum, I’ve learned how to create a triangle from the lenght of its sides with nodes, and I’ve transformed the process to Python code

This is the Python language version of the upper script. It only works for one triangle. It has worked for me

import clr

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

clr.AddReference(“RevitNodes”)
import Revit

from Revit.Elements import *

import clr
clr.AddReference(“DSCoreNodes”)
from DSCore import *

from itertools import *

define lists as inputs

list_sideA = IN[0]
list_sideB = IN[1]
list_sideC = IN[2]
list_alpha = IN[3]
list_beta = IN[4]
list_gamma = IN[5]
triangle_list = IN[6]

define first triangle

first_sideA = list_sideA[0]
first_sideB = list_sideB[0]
first_sideC = list_sideC[0]
first_alpha = list_alpha[0]
first_beta = list_beta[0]
first_gamma = list_gamma[0]

first triangle as Polygon

p1 = Point.Origin();
v1 = Vector.XAxis();
geometry1 = Geometry.Translate(p1, v1, first_sideB); # adicionar índice listas
v2 = Vector.ZAxis();
v3 = Vector.Rotate(v1, v2, first_alpha);
geometry2 = Geometry.Translate(p1, v3, first_sideC);
t4 = [geometry1, p1, geometry2];
polygon1 = Polygon.ByPoints(t4);
sidesPolygon1 = Geometry.Explode(polygon1);
diagonalA = List.GetItemAtIndex(sidesPolygon1,2);

After that, I built a process for, from the common side and with the same rules, creating the second triangle.

define third side vector

start_point_diagonalA = Curve.StartPoint(diagonalA);
end_point_diagonalA = Curve.StartPoint(diagonalA);
vector_diagonalA = Vector.ByTwoPoints(start_point_diagonalA,end_point_diagonalA);

repeat same process for second triangle

vector_side2B = Vector.Rotate(vector_diagonalA, v2, second_beta);
geometry2 = Geometry.Translate(p1, v3, first_sideC);
t4 = [geometry1, p1, geometry2];
polygon1 = Polygon.ByPoints(t4);

My problem is that I’ve a list of triangles, that I’ve ordered according their common sides, being the common side the first of each sublist of the last list of the lower image.

I need to replicate the process according the index of the common sides, independently the amount of triangles in the model.

Thanks a lot

Actualization:

I’ve found the sublists where diagonals are repeated, it means, the sublists where they can be found as non diagonal sides.