There is a DXF file, I wrote a function that receives the coordinates of each point in this format:
[ [0.0, 0.0, 0.0, 0.0, 10.0, 0.0], [0.0, 10.0, 0.0, 15.0, 10.0, 0.0], [15.0, 10.0, 0.0, 15.0, 10.0, 5.0], [15.0, 10.0, 5.0, 15.0, 13.0, 5.0] ] Code:
def getCoordinates(key): # Π€ΡΠ½ΠΊΡΠΈΡ ΠΏΠΎΠ»ΡΡΠ°Π΅Ρ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΡ XYZ, ΠΏΠΎ ΠΊΠ»ΡΡΡ # "AcDbLine\n" - Π»ΠΈΠ½ΠΈΡ, "AcDbPoint\n" - ΡΠΎΡΠΊΠ° ind = [] CoordList = [] for n, e in enumerate(ll): if key in e: ind.append(n) for sp in ind: a = ll[sp + 2:sp + 13] try: # ΠΡΠ»ΠΈ ΡΡΠΎ Π»ΠΈΠ½ΠΈΡ, ΡΠΎ Π²Π·ΡΡΡ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΡ Π½Π°ΡΠ°Π»ΡΠ½ΠΎΠΉ ΠΈ ΠΊΠΎΠ½Π΅ΡΠ½ΠΎ ΡΠΎΡΠ΅ΠΊ CoordList.append([float(a[0]), float(a[2]), float(a[4]), float(a[6]), float(a[8]), float(a[10])]) except: # ΠΡΠ»ΠΈ ΡΡΠΎ ΡΠΎΡΠΊΠ°, ΡΠΎ Π²Π·ΡΡΡ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΡ ΡΠΎΡΠΊΠΈ CoordList.append([float(a[0]), float(a[2]), float(a[4])]) return CoordList Also in this file the point is indicated, this is the point from which it is necessary to begin counting. The coordinates of the point also received [15.0, 13.0, 5.0]
I tried to create a dictionary of type 1:[ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΡ Π»ΠΈΠ½ΠΈΠΈ] but managed only to get the line on which the point is and that does not work correctly.
Here is the code:
for num, el in enumerate(getCoordinates("AcDbLine\n")): try: point = getCoordinates("AcDbPoint\n")[0] # ΠΠΎΠ»ΡΡΠ°Π΅Ρ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΡ ΡΠΎΡΠΊΠΈ Π΄Π»Ρ ΡΡΠ°Π²Π½Π΅Π½ΠΈΡ except IndexError: # ΠΡΠ»ΠΈ ΡΠΎΡΠΊΠ° Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½Π°, ΠΏΡΠ΅ΠΊΡΠ°ΡΠΈΡΡ Π΄Π°Π»ΡΠ½Π΅ΠΉΡΠΈΠ΅ Π΄Π΅ΠΉΡΡΠ²ΠΈΡ print ("Π’ΠΎΡΠΊΠ° ΠΎΡΡΡΠ΅ΡΠ° Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½Π°") break if point == el[:3] or point == el[4:]: #ΠΡΠ»ΠΈ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΡ ΡΠΎΡΠΊΠΈ ΡΠΎΠ²ΠΏΠ°Π΄Π°ΡΡ Ρ Π»ΠΈΠ½ΠΈΠ΅ΠΉ D[1] = [el, GetLength("AcDbLine\n", num)] # ΠΠ΅ΡΠ²Π°Ρ Π»ΠΈΠ½ΠΈΡ, ΠΊΠΎΡΠΎΡΠ°Ρ ΡΠΎΠ²ΠΏΠ°Π΄Π°Π΅Ρ Ρ ΡΠΎΡΠΊΠΎΠΉ ΠΈΠΌΠ΅Π΅Ρ ΠΈΠ½Π΄Π΅ΠΊΡ 1 The essence of the problem is to write these coordinates in such a way that they follow each other starting from the point of reference. The starting point can stand anywhere, but at the contact points of two segments.
For greater clarity, I drew a picture. Red numbers indicate the order to be obtained.
Maybe I'm not doing everything right and who will propose a better solution? 
So in DXF the point looks
AcDbPoint 10 15.0 20 13.0 30 5.0 0 and so the line
AcDbLine 10 15.0 20 10.0 30 5.0 11 15.0 21 13.0 31 5.0 0 Point as a separate element and is set manually just as a line is drawn.