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? enter image description here

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.

    1 answer 1

    Try this:

     def to_my_dict(): prev_point = getCoordinates("AcDbPoint\n") if prev_point: point = prev_point[0] else: return "Π’ΠΎΡ‡ΠΊΠ° отсчСта Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½Π°" my_dict = {} all_lines = getCoordinates("AcDbLine\n") count = 1 line_count = len(all_lines) while line_count: for el in all_lines: if point == el[:3] or point == el[3:]: my_dict[count] = el # линия, Π² ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΉ Π΅ΡΡ‚ΡŒ Ρ‚ΠΎΡ‡ΠΊΠ° count += 1 line_count -= 1 if point == el[:3]: point = el[3:] else: point = el[:3] return my_dict print(to_my_dict()) 

    Maybe I did not quite understand you correctly, if this is not what is needed - leave a comment and explain the question in more detail.

    • A little bit wrong. With the getCoordinates () function, I can get both a line ("AcDbLine \ n") and a point (AcDbPoint \ n). Point as a separate item. It turns out I wanted the first condition to compare the coordinates of a point with the coordinates of the line, and if one line coincides with a point, then assign the key 1 to it. point in the previous line, then assign key 2 and so go through all the lines ... Yes, D dictionary, thanks for the comment) A bit confusing, but I hope I managed to tell a little more clearly. - user275841
    • I edited the answer, substituted your values, it seems to work, note that I replace the next point in the line, maybe I'm wrong - Igor Lavrynenko
    • Yes, it works, thanks! - user275841