Python Forum
dxfgrabber-return lines start point
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dxfgrabber-return lines start point
#1
Hi 
i wrote the below code to return the start point of the lines in drawing, but it return error:

import dxfgrabber
dwg = dxfgrabber.readfile("test.dxf")
print("DXF version:{} ".format(dwg.dxfversion))
all_lines = [entity for entity in dwg.entities if entity.line.start]
for line in all_lines:
    print(line.start)
Error:
Traceback (most recent call last):     all_lines = [entity for entity in dwg.entities if entity.line.start] AttributeError: 'Line' object has no attribute 'line'
Reply
#2
OK, that's something different. Now, what the Traceback says:
'Line' object has no attribute 'line'
It's as clear as it gets - entity has no such attribute line. And if you are still not convinced - you check the docs just to confirm what the Traceback says.
What you want to use is entity.dxftype=='LINE':

import dxfgrabber
dwg = dxfgrabber.readfile("test.dxf")
print("DXF version:{} ".format(dwg.dxfversion))
all_lines = [entity for entity in dwg.entities if entity.dxftype=='LINE']
for line in all_lines:
    print(line.start)
Reply
#3
(Feb-26-2017, 12:10 PM)buran Wrote: OK, that's something different. Now, what the Traceback says:
'Line' object has no attribute 'line'
It's as clear as it gets - entity has no such attribute line. And if you are still not convinced - you check the docs just to confirm what the Traceback says.
What you want to use is entity.dxftype=='LINE':

import dxfgrabber
dwg = dxfgrabber.readfile("test.dxf")
print("DXF version:{} ".format(dwg.dxfversion))
all_lines = [entity for entity in dwg.entities if entity.dxftype=='LINE']
for line in all_lines:
    print(line.start)

it is working , thanks, from the way you explain, i got feeling that i have a problem with the fundamentals.
Reply
#4
I don't know if it is problem with the fundamentals or inexperience (e.g. reading the docs, the Traceback).
As I said in the other thread - you should learn reading the docs of the packages. You should also learn to read and understand the Traceback. It s' prety clear on which line the error is, how you get there and what the problem is.

By the way, note that in this particular case it's pure coincidence that the error says 'Line' object. It could be any other shape type which is first in dwg.entities. eg. the other day when you first post the question in the other thread, I've got error for Spline object
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Matplotlib: How do I plot lines with different end point in the same graph? JaneTan 0 1,578 Feb-28-2021, 11:56 AM
Last Post: JaneTan
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 5,827 Aug-10-2020, 11:01 PM
Last Post: medatib531
  connecting the first point to the last point Matplotlib omar_mohsen 0 4,588 Jan-15-2020, 01:23 PM
Last Post: omar_mohsen
  What's the difference b/w assigning start=None and start=" " Madara 1 2,315 Aug-06-2018, 08:23 AM
Last Post: buran
  dxfgrabber elhetch 5 6,552 Mar-28-2017, 05:28 PM
Last Post: nilamo
  dxfgrabber elhetch 2 3,523 Feb-23-2017, 04:12 PM
Last Post: Larz60+
  dxfgrabber elhetch 7 8,608 Feb-21-2017, 11:15 AM
Last Post: elhetch

Forum Jump:

User Panel Messages

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