Python Forum
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dxfgrabber
#1
Hello,
 i am not sure why the below code doesnot return the layers as expected.

import dxfgrabber

test = dxfgrabber.readfile("test.dxf")
test = dxfgrabber.layers("test.dxf")
print("DXF version:{} ".format(test.dxfversion))
print LayerTable.names("test")
Reply
#2
Did you read the docs and had a look at the howtos?
For start don't use test as name for everything
Reply
#3
what about that:

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']
print all_lines

but i got that when i run the code..
DXF version:AC1027
[<dxfgrabber.dxfentities.Line object at 0x03147F10>, <dxfgrabber.dxfentities.Line object at 0x03147F90>, <dxfgrabber.dxfentities.Line object at 0x03160410>]
Reply
#4
yes, that's all (3) lines from the drawing. Each has layers property which returns LayerTable
not tested, but something like this:
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:
   for layer in line.layers:
       print layer.name, layer.color
EDIT: this part
    for layer in line.layers:
       print layer.name, layer.color
is not correct and would rise an exception. see the code my next post
Reply
#5
I had a more detailed look at the module and experimented with sample dxf files.

import dxfgrabber
dwg = dxfgrabber.readfile("test.dxf")
print("DXF version:{} ".format(dwg.dxfversion))

# print LayerTable.names() - all layers in the Drawing
print('available layers: {}'.format(', '.join(dwg.layers.names())))

# OR
# print layer for every entity of type LINE - uncomment next lines
# all_lines = [entity for entity in dwg.entities if entity.dxftype == 'LINE']
# for line in all_lines:
#     print(line.layer)
Reply
#6
(Feb-20-2017, 02:57 PM)buran Wrote: I had a more detailed look at the module and experimented with sample dxf files.

import dxfgrabber
dwg = dxfgrabber.readfile("test.dxf")
print("DXF version:{} ".format(dwg.dxfversion))

# print LayerTable.names() - all layers in the Drawing
print('available layers: {}'.format(', '.join(dwg.layers.names())))

# OR
# print layer for every entity of type LINE - uncomment next lines
# all_lines = [entity for entity in dwg.entities if entity.dxftype == 'LINE']
# for line in all_lines:
#     print(line.layer)

thanks for that , it is working , but i dont understand how did you get that from, i have read the documentation and i cannt figure it out, sorry about that, but i am new in coding.
Reply
#7
It's really by reading the docs. It becomes easier with the practice. Of course it depends also on the quality and completness of the documentation.


Reading the dxf file returns object of type Drawing. next you can see that Drawing has layers property that returns instance of LayerTable class. Then you see that LayerTable class has names method that returns sorted list of all layer's names.
You should read the docs to get idea of the properties and methods of LayerTable and Layer classes.
Reply
#8
(Feb-21-2017, 11:06 AM)buran Wrote: It's really by reading the docs. It becomes easier with the practice. Of course it depends also on the quality and completness of the documentation.


Reading the dxf file returns object of type Drawing. next you can see that Drawing has layers property that returns instance of LayersTable class. Then you see that LayerTable class has names method that returns sorted list of all layer's names.
You should read the docs to get idea of the properties and methods of LayerTable and Layer classes.

thank you , i will follow your advice.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  dxfgrabber elhetch 5 6,492 Mar-28-2017, 05:28 PM
Last Post: nilamo
  dxfgrabber-return lines start point elhetch 3 4,645 Feb-26-2017, 12:28 PM
Last Post: buran
  dxfgrabber elhetch 2 3,471 Feb-23-2017, 04:12 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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