libraries - Python: How to use a third-party library -
i feeling stupid. python beginner , use third-party libraries, such dxfgrabber.
i have played following, given in section, don't know further:
import dxfgrabber dxf = dxfgrabber.readfile("1.dxf") print("dxf version: {}".format(dxf.dxfversion)) header_var_count = len(dxf.header) layer_count = len(dxf.layers) entity_count = len(dxf.entities) print layer_count print entity_count print dxf.layers
output far is:
dxf version: ac1009 6 2 <dxfgrabber.layers.layertable object @ 0x10f42b590>
my questions:
so know there 6 layers , 2 entities. how can further information like: layer name, entities?
how can access entities (for example know there 2 lines)? how can lines?
i write code entities (such lines) displayed on canvas.
it seems library should ready use, maybe people more knowledge python me.
try example:
for layer in dxf.layers: print layer.name, layer.color
explanation:
the output of last print command indicates dxf.layers
layertable
object. in documentation can see layertable
object has property:
layertable.__iter__() iterate on layers, yields layer objects.
this means can iterated in loop or whatever construction takes iterable. in case of entities can this:
all_layer_0_entities = [entity entity in dwg.entities if entity.layer == '0']
here applies same principle, object dwg.entities being iterated yielding entity in each iteration.
you right documentation use more examples. see this post of that.
Comments
Post a Comment