Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lists-compare lists
#8
@snippsat: the OP is not clear in the explanations. S/he works with CAD dxf files and it looks like s/he want to compare the end of one line with start of the next line and see if they are connected (i.e. coordinates of the end (x,y[,z]) of line1 are the same as the start (x,y[,z]) of the line2). That's why set will not work in this case.
However I'm afraid it's not that simple for several reasons and here are some of them:
1. the lines in the list that he creates is not necessary drawn in the same order as they appear on the drawing, i.e. even if two lines are connected, they not necessary have consecutive indexes in that list
2. there may be one more groups of connected lines, not necessary connected with one another
3. there are different type of elements - lines, polylines, rays, etc and many more. each with its certain specifics.
4. there may be different layers in the drawing. I don't know if it's possible to have two lines that appear connected, but being drawn on different layers and how you shall treat these.


I'm not familiar with CAD and with the input file the OP works with. I started to look at the dxfgrabber packaged few days ago to help OP, but s/he doesn't dive into the docs.

import dxfgrabber
from collections import deque

def compare_lines(line1,line2):
   print 'line1: {}\nline1 start:{}\nline1 end: {}\nline2: {}\nline2 start:{}\nline2 end: {}'.format(line1, line1.start, line1.end, line2, line2.start, line2.end)
   if line1.end == line2.start:
       return 'one shape'
   else:
       return 'not one shape'

dwg = dxfgrabber.readfile("./samples/bike.dxf")
print("DXF version:{} ".format(dwg.dxfversion))

all_lines = [entity for entity in dwg.entities if entity.dxftype=='LINE']
# create second list with first line from the original list moved to the end
if all_lines:
   all_lines2 = all_lines[1:]
   first_line = all_lines[0]
   all_lines2.append(first_line)

   for line1, line2 in zip (all_lines, all_lines2):
       print compare_lines(line1, line2)

   # anoteher way - using collections.deque
   dq1 = deque(all_lines)
   dq2 = deque(all_lines)
   dq2.rotate(1)

   for line1, line2 in zip (dq1, dq2):
       print compare_lines(line1, line2)
Reply


Messages In This Thread
Lists-compare lists - by elhetch - Mar-01-2017, 11:07 AM
RE: Lists-compare lists - by buran - Mar-01-2017, 11:10 AM
RE: Lists-compare lists - by elhetch - Mar-01-2017, 11:28 AM
RE: Lists-compare lists - by snippsat - Mar-01-2017, 11:46 AM
RE: Lists-compare lists - by elhetch - Mar-01-2017, 12:15 PM
RE: Lists-compare lists - by Larz60+ - Mar-01-2017, 12:27 PM
RE: Lists-compare lists - by snippsat - Mar-01-2017, 02:26 PM
RE: Lists-compare lists - by buran - Mar-01-2017, 02:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Using Lists as Dictionary Values bfallert 8 390 Apr-21-2024, 06:55 AM
Last Post: Pedroski55
  problem with print lists MarekGwozdz 4 736 Dec-15-2023, 09:13 AM
Last Post: Pedroski55
  python convert multiple files to multiple lists MCL169 6 1,615 Nov-25-2023, 05:31 AM
Last Post: Iqratech
  Lists blake7 6 806 Oct-06-2023, 12:46 PM
Last Post: buran
  Trying to understand strings and lists of strings Konstantin23 2 799 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  Why do the lists not match? Alexeyk2007 3 846 Jul-01-2023, 09:19 PM
Last Post: ICanIBB
  ''.join and start:stop:step notation for lists ringgeest11 2 2,463 Jun-24-2023, 06:09 AM
Last Post: ferdnyc
  Need help with sorting lists as a beginner Realist1c 1 770 Apr-25-2023, 04:32 AM
Last Post: deanhystad
  Pip lists the module but python does not find it Dato 2 1,305 Apr-13-2023, 06:40 AM
Last Post: Dato
  Generate lists of devices and partitions from /proc/partitions? DachshundDigital 1 787 Feb-28-2023, 10:55 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020