Make a diagonalized polygon with specific lengths of segments (Revit-Dynamo)

Hello to everyone

Here is my problem:

  1. The user defines the structure of a diagonalized polygon from a model sketch in Revit, to be translated to Dynamo, that has a node for Python scripts.


2. Each line has a specific and unique length. According to congruence of triangles, if I have the lengths of the three sides of a triangle, that triangle shall have the same angles. I’ve decided to assign to each line an index, so the user will assign a distance, in numeric terms, to the line. The index comes from the order of lines I’ve traced in Revit.

  1. The relation of index and distance is controlled through an Excel table. {Line 0, Length=6: Line 1, Length=8: Line 2, Length=7: …}

Problem in Dynamo

This is the code in Python I’ve tried:

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 *



# definir listas de entrada

list_sideA = IN[0]
list_sideB = IN[1]
list_sideC = IN[2]
list_alpha = IN[3]
list_beta = IN[4]
list_gamma = IN[5]
list_triangles = IN[6]
list_distances = IN[7]
list_ordered_distances = IN[8]


# definir primer elemento

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]


# Primer triángulo, a partir de la línea 0 y del punto de orígen (0,0)

p1 = Point.Origin();
v1 = Vector.XAxis();
geometry1 = Geometry.Translate(p1, v1, first_sideB); 
v2 = Vector.ZAxis();
v3 = Vector.Rotate(v1, v2, first_alpha);
geometry2 = Geometry.Translate(p1, v3, first_sideC);
first_set_of_points = [geometry1, p1, geometry2];
polygon1 = Polygon.ByPoints(first_set_of_points);

# definir diagonal del primer triángulo

sidesPolygon1 = Geometry.Explode(polygon1);
diagonalA = List.GetItemAtIndex(sidesPolygon1,2);
p4 = diagonalA.PointAtParameter(0)
start_point_diagonalA = diagonalA.PointAtParameter(0);
end_point_diagonalA = diagonalA.PointAtParameter(1);
vector_diagonalA = Vector.ByTwoPoints(start_point_diagonalA, end_point_diagonalA);

# definir lados externos del primer triángulo

side1_lineA = List.GetItemAtIndex(sidesPolygon1,0)
side2_lineA = List.GetItemAtIndex(sidesPolygon1,1)

# definir índices de los primeros 2 triángulos

first_and_second_triangle_indexes = List.GetItemAtIndex(list_triangles,0)

first_triangle_indexes = List.GetItemAtIndex(first_and_second_triangle_indexes,0)

second_triangle_indexes = List.GetItemAtIndex(first_and_second_triangle_indexes,1)

first_triangle_indexes_0 = List.GetItemAtIndex(first_triangle_indexes,0)
first_triangle_indexes_1 = List.GetItemAtIndex(first_triangle_indexes,1)
first_triangle_indexes_2 = List.GetItemAtIndex(first_triangle_indexes,2)

# asociar lados a índices de la lista genérica

diccionario_primer_triangle = { diagonalA : first_triangle_indexes_0 , side1_lineA : first_triangle_indexes_1 , side2_lineA : first_triangle_indexes_2 }

asociar_key_triangle_1 = diccionario_primer_triangle.keys()
asociar_values_triangle_1 = diccionario_primer_triangle.values()

# definir segundo triángulo, a partir de la diagonal resultante

second_sideA = list_sideA[1]
second_sideB = list_sideB[1]
second_sideC = list_sideC[1]
second_alpha = list_alpha[1]
second_beta = list_beta[1]
second_gamma = list_gamma[1]

vector_side2B = Vector.Rotate(vector_diagonalA, v2, second_beta);
second_origin = Geometry.Translate(start_point_diagonalA, vector_side2B, first_sideC);
second_set_of_points = [start_point_diagonalA, second_origin, end_point_diagonalA];
polygon2 = Polygon.ByPoints(second_set_of_points);

# definir lados segundo triángulo

sidesPolygon2 = Geometry.Explode(polygon2)

side1_lineB = List.GetItemAtIndex(sidesPolygon2,0)
side2_lineB = List.GetItemAtIndex(sidesPolygon2,1)

# repetir proceso de indexación segundo triángulo

second_triangle_indexes_0 = List.GetItemAtIndex(second_triangle_indexes,0)
second_triangle_indexes_1 = List.GetItemAtIndex(second_triangle_indexes,1)
second_triangle_indexes_2 = List.GetItemAtIndex(second_triangle_indexes,2)


diccionario_segundo_triangle = { diagonalA : second_triangle_indexes_0 , side1_lineB : second_triangle_indexes_1 , side2_lineB : second_triangle_indexes_2 }

asociar_key_triangle_2 = diccionario_segundo_triangle.keys()
asociar_values_triangle_2 = diccionario_segundo_triangle.values()



#termina proceso para los 2 primeros triángulos, los mínimos para generar un polígono

# asociar lados a índices de la lista genérica

#definir listas genéricas para los triángulos restantes

n_list_triangles = List.Count(list_triangles)
n_list_distances = List.Count(list_distances)
n_list_ordered_distances = List.Count(list_ordered_distances)

sequence_index_ordered_distances = range(2,n_list_ordered_distances);

list_dimensions = [list_sideA, list_sideB, list_sideC, list_alpha, list_beta, list_gamma]

# probar ciclos, luego de relacionar distancias con índices

n_sideA = list_sideA[2:n_list_distances]
n_sideB = list_sideB[2:n_list_distances]
n_sideC = list_sideC[2:n_list_distances]
n_alpha = list_alpha[2:n_list_distances]
n_beta = list_beta[2:n_list_distances]
n_gamma = list_gamma[2:n_list_distances]

#crear diccionarios que relacionen distancias con sus respectivos índices en la estructura topológica del boceto




#sustituir por ciclo después de probar

# buscar un elemento que sea diagonal y lado


# if true, buscar ítem con índice y realizar proceso; if false, buscar otro valor



# definir algoritmo de creación de triángulos a partir de los índices


OUT = polygon1, polygon2

I define the first and second triangles from the lengths of their segments and the indexes of their lines in the sketch in Revit. I want to iterate that process, knowing that the first element of a pair of group of triangle segments is a diagonal, or, I mean, a side that two triangles within the polygon share, or have in common.

Thanks a lot.

This image may help to understand I’m trying to do: