dxfgrabber - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: dxfgrabber (/thread-2120.html) |
dxfgrabber - elhetch - Feb-20-2017 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") RE: dxfgrabber - buran - Feb-20-2017 Did you read the docs and had a look at the howtos? For start don't use test as name for everything
RE: dxfgrabber - elhetch - Feb-20-2017 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>] RE: dxfgrabber - buran - Feb-20-2017 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.colorEDIT: this part for layer in line.layers: print layer.name, layer.coloris not correct and would rise an exception. see the code my next post RE: dxfgrabber - buran - Feb-20-2017 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) RE: dxfgrabber - elhetch - Feb-21-2017 (Feb-20-2017, 02:57 PM)buran Wrote: I had a more detailed look at the module and experimented with sample dxf files. 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. RE: dxfgrabber - buran - Feb-21-2017 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.
RE: dxfgrabber - elhetch - Feb-21-2017 (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. thank you , i will follow your advice. |