擅长:python、mysql、java
<p>试试这个</p>
<pre><code>import ezdxf
from ezdxf.tools.standards import setup_dimstyle
DIM_TEXT_STYLE = ezdxf.options.default_dimension_text_style
# create a new DXF R2010 drawing, official DXF version name: 'AC1024'
doc = ezdxf.new('R2010',setup=True)
#create a new dimstyle
setup_dimstyle(doc,
name='EZDXF1',
fmt='EZ_MM_0.1_H25_MM',
blk=ezdxf.ARROWS.closed_filled,
style=DIM_TEXT_STYLE,
)
dimstyle = doc.dimstyles.get('EZDXF1')
#keep dim line with text
dimstyle.dxf.dimtmove=0
msp = doc.modelspace()
points=[(0,0),(20,0),(20,10),(0,10),(0,0)]
#draw rectang
msp.add_lwpolyline(points)
msp.add_aligned_dim(p1=(0, 0), p2=(0, 10),distance=1, dimstyle='EZDXF1')
msp.add_aligned_dim(p1=(0, 10), p2=(20, 10),distance=11, dimstyle='EZDXF1')
msp.add_aligned_dim(p1=(0, 0), p2=(20, 10),distance=1, dimstyle='EZDXF1',text="test")
doc.saveas('dim.dxf')
</code></pre>