0

I have a dxf files and I wan't to search points from a polyline in python. However, my files sections are differents than a dxf than I succeded to display points.

I explain : In the dxf I succeded, polylines were in the ENTITITES section. So I do this to display points :

polylines = msp.query('POLYLINE')
for polyline in polylines:
        #print('Polyline #{}'.format(polyline.dxf.handle))
        #print(str(polyline))
        for i, location in enumerate(polyline.points()):
            print('Point at index {}: {}'.format(i, location))

PROBLEM In my dxf file, polylines are in the BLOCKS section. So I can't succed to access to polylines points. Here is an extract of the dxf :

SECTION
  2
BLOCKS
  0
BLOCK
  5
89
100
AcDbEntity
  8
0
100
AcDbBlockBegin
  2
*MODEL_SPACE
 70
0
 10
0
 20
0
  0
ENDBLK
  5
8A
100
AcDbEntity
  8
0
100
AcDbBlockEnd
  0
BLOCK
  5
8B
100
AcDbEntity
  8
0
100
AcDbBlockBegin
  2
*PAPER_SPACE
 70
0
 10
0
 20
0
  0
ENDBLK
  5
8C
100
AcDbEntity
  8
0
100
AcDbBlockEnd
  0
BLOCK
  5
6
100
AcDbEntity
  8
0
100
AcDbBlockBegin
  2
1{SEWNPRODUCTTYPE}16_0
 70
0
 10
0
 20
0
 30
0
  3
1{SEWNPRODUCTTYPE}16_0
  1

  0
POLYLINE
  5
3E
100
AcDbEntity
  8
Pattern Perimeter
100
AcDb3dPolyline
 62
4
 66
1
 10
0
 20
0
 30
0
 70
8
 40
0
 41
0
  0
VERTEX
  5
8D
100
AcDbEntity
  8
Pattern Perimeter
100
AcDbVertex
100
AcDb3dPolylineVertex
 62
4
 10
125.672850422868
 20
218.357119515253
 30
0
 70
0
  0

-> We see vertex in PatternPerimeter Layer. I wan't to catch points.

Somebody can help me please ?

Thank you

marie
  • 1

1 Answers1

0

Is your question about accessing a polyline within a block?

I'm not sure if I'm right either... try the below!

blocks = msp.query('INSERT')
for b in blocks:
    ex = b.explode()
    polylines = ex.query('POLYLINE')
    for polyline in polylines:
        # do something..

To use an object inside a block,

you must first release the block and access it.

Check out the link here!


or

There is also a way to access the inside directly!

blocks = self.msp.query('INSERT')
for b in blocks:
    for e in b.block().entity_space.entities:
    if e.dxftype() == 'POLYLINE':
        # do something..

here

kimms
  • 101
  • 1
  • 9