1# Purpose: using DIMENSION horizontal, vertical and rotated
2# Created: 29.12.2018
3# Copyright (c) 2018-2019, Manfred Moitzi
4# License: MIT License
5from typing import TYPE_CHECKING
6import sys
7import math
8import pathlib
9import random
10import ezdxf
11from ezdxf.tools.standards import setup_dimstyle
12from ezdxf.math import Vec3, UCS
13import logging
14
15if TYPE_CHECKING:
16    from ezdxf.eztypes import DimStyle, DimStyleOverride
17
18# ========================================
19# IMPORTANT:
20# this script uses f-strings (Python 3.6)
21# ========================================
22if sys.version_info < (3, 6):
23    print("This script requires Python 3.6 (f-strings)")
24    sys.exit()
25
26# ========================================
27# Setup logging
28# ========================================
29logging.basicConfig(level='WARNING')
30
31# ========================================
32# Setup your preferred output directory
33# ========================================
34OUTDIR = pathlib.Path('~/Desktop/Outbox').expanduser()
35if not OUTDIR.exists():
36    OUTDIR = pathlib.Path()
37
38# ========================================
39# Default text attributes
40# ========================================
41TEXT_ATTRIBS = {
42    'height': .25,
43    'style': ezdxf.options.default_dimension_text_style,
44}
45DIM_TEXT_STYLE = ezdxf.options.default_dimension_text_style
46
47# =======================================================
48# Discarding dimension rendering is possible
49# for BricsCAD, but is incompatible to AutoCAD -> error
50# =======================================================
51BRICSCAD = False
52
53
54def set_text_style(doc, textstyle=DIM_TEXT_STYLE, name='EZDXF'):
55    if doc.dxfversion == 'AC1009':
56        return
57    dimstyle = doc.dimstyles.get(name)  # type: DimStyle
58    dimstyle.dxf.dimtxsty = textstyle
59
60
61def linear_tutorial(dxfversion='R12'):
62    doc = ezdxf.new(dxfversion, setup=True)
63    msp = doc.modelspace()
64    msp.add_line((0, 0), (3, 0))
65    msp.add_line((0, 7), (10, 0))
66
67    # horizontal DIMENSION
68    # Default DimStyle EZDXF: 1 drawing unit == 1m; scale 1: 100; length_factor=100 -> measurement in cm
69    #
70    # base: defines the dimension line, ezdxf accepts any point on the dimension line
71    # p1: defines the start point of the first extension line, which also defines the first point to measure
72    # p2: defines the start point of the second extension line, which also defines the second point to measure
73
74    dim = msp.add_linear_dim(base=(3, 2), p1=(0, 0), p2=(3, 0), dimstyle='EZDXF', override={'dimtxsty': 'OpenSans'})
75    # Necessary second step, to create the BLOCK entity with the DIMENSION geometry.
76    # ezdxf supports DXF R2000 attributes for DXF R12 rendering, but they have to be applied by the DIMSTYLE override
77    # feature, this additional attributes are not stored in the XDATA section of the DIMENSION entity, they are just
78    # used to render the DIMENSION entity.
79    # The return value `dim` is not a DIMENSION entity, instead a DimStyleOverride object is returned, the DIMENSION
80    # entity is stored as dim.dimension, see also ezdxf.override.DimStyleOverride class.
81    dim.render()
82
83    # rotated DIMENSION without `override` uses ezdxf.options.default_dimension_text_style (OpenSansCondensed-Light)
84    # angle: defines the angle of the dimension line in relation to the x-axis of the WCS or UCS, measurement is the
85    # distance between first and second measurement point in direction of `angle`
86    dim2 = msp.add_linear_dim(base=(10, 2), p1=(7, 0), p2=(10, 0), angle=-30, dimstyle='EZDXF',
87                              override={
88                                  'dimdle': 0,
89                                  'dimdec': 2,
90                                  'dimtfill': 2,  # custom text fill
91                                  'dimtfillclr': 4,  # cyan
92                              })  # type: DimStyleOverride
93    # Some properties have setter methods for convenience, this is also the reason for not calling dim2.render()
94    # automatically.
95    dim2.set_arrows(blk=ezdxf.ARROWS.closed_filled, size=.25)
96    dim2.set_text_align(halign='right')
97    dim2.render()
98
99    doc.set_modelspace_vport(height=5, center=(5, 0))
100    doc.saveas(OUTDIR / f'dim_linear_{dxfversion}_tutorial.dxf')
101
102
103def example_background_fill(dxfversion='R12'):
104    """
105    This example shows the background fill feature, ezdxf uses MTEXT for this feature and has no effect in DXF R12.
106
107    """
108    doc = ezdxf.new(dxfversion, setup=True)
109    msp = doc.modelspace()
110    msp.add_line((0, 2.2), (10, 2.2))
111
112    dim = msp.add_linear_dim(base=(0, 2), p1=(0, 0), p2=(3, 0), dimstyle='EZDXF',
113                             override={
114                                 'dimtfill': 1,  # background color
115                             })  # type: DimStyleOverride
116    dim.set_text('bgcolor')
117    dim.render()
118
119    dim = msp.add_linear_dim(base=(0, 2), p1=(5, 0), p2=(8, 0), dimstyle='EZDXF',
120                             override={
121                                 'dimtfill': 2,  # custom text fill
122                                 'dimtfillclr': 4,  # cyan
123                             })  # type: DimStyleOverride
124    dim.set_text('cyan')
125    dim.render()
126    doc.saveas(OUTDIR / f'background_fill_example_{dxfversion}.dxf')
127
128
129def example_for_all_text_placings_R12():
130    doc = ezdxf.new('R12', setup=True)
131    example_for_all_text_placings(doc, 'dim_linear_text_placing_R12.dxf')
132
133
134def example_for_all_text_placings_ucs_R12():
135    ucs = UCS(origin=(10, 10, 0), ux=(3, 1, 0), uz=(0, 0, 1))
136    doc = ezdxf.new('R12', setup=True)
137    example_for_all_text_placings(doc, 'dim_linear_text_placing_ucs_R12.dxf', ucs)
138
139
140def example_for_all_text_placings_in_space_R12():
141    ucs = UCS(ux=(1, 1, 0), uy=(0, 0, 1))
142    doc = ezdxf.new('R12', setup=True)
143    example_for_all_text_placings(doc, 'dim_linear_text_placing_in_space_R12.dxf', ucs)
144
145
146def example_for_all_text_placings_R2007():
147    doc = ezdxf.new('R2007', setup=True)
148    set_text_style(doc)
149    example_for_all_text_placings(doc, 'dim_linear_text_placing_R2007.dxf')
150
151
152def example_for_all_text_placings_ucs_R2007():
153    ucs = UCS(origin=(10, 10, 0), ux=(3, 1, 0), uz=(0, 0, 1))
154    doc = ezdxf.new('R2007', setup=True)
155    set_text_style(doc)
156    example_for_all_text_placings(doc, 'dim_linear_text_placing_ucs_R2007.dxf', ucs)
157
158
159def example_for_all_text_placings_in_space_R2007():
160    ucs = UCS(origin=(20, 20, 0)).rotate_local_x(math.radians(45)).rotate_local_z(math.radians(45))
161    doc = ezdxf.new('R2007', setup=True)
162    set_text_style(doc)
163    example_for_all_text_placings(doc, 'dim_linear_text_placing_in_space_R2007.dxf', ucs)
164
165
166def example_for_all_text_placings(doc, filename, ucs=None):
167    """
168    This example shows many combinations of dimension text placing by `halign`, `valign` and user defined location
169    override.
170
171    Args:
172        doc: DXF drawing
173        filename: file name for saving
174        ucs: user defined coordinate system
175
176    """
177
178    def add_text(lines, insert):
179        insert += (.2, 0)
180        attribs = dict(TEXT_ATTRIBS)
181        line_space = .4
182        delta = Vec3(0, line_space, 0)
183        for line in lines:
184            text = msp.add_text(line, dxfattribs=attribs).set_pos(insert)
185            if ucs:
186                text.transform(ucs.matrix)
187            insert -= delta
188
189    msp = doc.modelspace()
190    setup_dimstyle(doc,
191                   name='TICK',
192                   fmt='EZ_M_100_H25_CM',
193                   style=DIM_TEXT_STYLE,
194                   )
195    setup_dimstyle(doc,
196                   name='ARCHTICK',
197                   fmt='EZ_M_100_H25_CM',
198                   blk=ezdxf.ARROWS.architectural_tick,
199                   style=DIM_TEXT_STYLE,
200                   )
201    setup_dimstyle(doc,
202                   name='CLOSEDBLANK',
203                   fmt='EZ_M_100_H25_CM',
204                   blk=ezdxf.ARROWS.closed_blank,
205                   style=DIM_TEXT_STYLE,
206                   )
207
208    def text(dimstyle, x, y, halign, valign, oblique=0):
209        """
210        Default dimension text placing
211
212        Args:
213            dimstyle: dimstyle to use
214            x: start point x
215            y: start point y
216            halign: horizontal text alignment - `left`, `right`, `center`, `above1`, `above2`, requires DXF R2000+
217            valign: vertical text alignment `above`, `center`, `below`
218            oblique: angle of oblique extension line, 0 = orthogonal to dimension line
219
220        """
221        dimattr = {}
222        if oblique:
223            dimattr['oblique_angle'] = oblique
224
225        base = (x, y + 2)
226        # wide
227        dim = msp.add_linear_dim(base=base, p1=(x, y), p2=(x + 5, y), dimstyle=dimstyle,
228                                 dxfattribs=dimattr)  # type: DimStyleOverride
229        dim.set_text_align(halign=halign, valign=valign)
230        dim.render(ucs=ucs, discard=BRICSCAD)
231
232        add_text([f'halign={halign}', f'valign={valign}', f'oblique={oblique}'], insert=Vec3(x, y))
233
234        # narrow
235        dim = msp.add_linear_dim(base=base, p1=(x + 7, y), p2=(x + 7.3, y), dimstyle=dimstyle,
236                                 dxfattribs=dimattr)  # type: DimStyleOverride
237        dim.set_text_align(halign=halign, valign=valign)
238        dim.render(ucs=ucs, discard=BRICSCAD)
239
240        # arrows inside, text outside
241
242        dim = msp.add_linear_dim(base=base, p1=(x + 10, y), p2=(x + 10.9999, y), dimstyle=dimstyle,
243                                 override={'dimdec': 2},
244                                 dxfattribs=dimattr)  # type: DimStyleOverride
245        dim.set_text_align(halign=halign, valign=valign)
246        dim.render(ucs=ucs, discard=BRICSCAD)
247
248        # narrow and force text inside
249        dim = msp.add_linear_dim(base=base, p1=(x + 14, y), p2=(x + 14.3, y), dimstyle=dimstyle,
250                                 override={'dimtix': 1},
251                                 dxfattribs=dimattr)  # type: DimStyleOverride
252        dim.set_text_align(halign=halign, valign=valign)
253        dim.render(ucs=ucs, discard=BRICSCAD)
254
255    def user_text_free(dimstyle, x=0, y=0, leader=False):
256        """
257        User defined dimension text placing.
258
259        Args:
260            dimstyle: dimstyle to use
261            x: start point x
262            y: start point y
263            leader: use leader line if True
264
265        """
266        override = {
267            'dimdle': 0.,
268            'dimexe': .5,  # length of extension line above dimension line
269            'dimexo': .5,  # extension line offset
270            'dimtfill': 2,  # custom text fill
271            'dimtfillclr': 4  # cyan
272        }
273
274        base = (x, y + 2)
275        dim = msp.add_linear_dim(base=base, p1=(x, y), p2=(x + 3, y), dimstyle=dimstyle,
276                                 override=override)  # type: DimStyleOverride
277        location = Vec3(x + 3, y + 3, 0)
278        dim.set_location(location, leader=leader)
279        dim.render(ucs=ucs, discard=BRICSCAD)
280        add_text([f'usr absolute={location}', f'leader={leader}'], insert=Vec3(x, y))
281
282        x += 4
283        dim = msp.add_linear_dim(base=base, p1=(x, y), p2=(x + 3, y), dimstyle=dimstyle,
284                                 override=override)  # type: DimStyleOverride
285        relative = Vec3(-1, +1)  # relative to dimline center
286        dim.set_location(relative, leader=leader, relative=True)
287        dim.render(ucs=ucs, discard=BRICSCAD)
288        add_text([f'usr relative={relative}', f'leader={leader}'], insert=Vec3(x, y))
289
290        x += 4
291        dim = msp.add_linear_dim(base=base, p1=(x, y), p2=(x + 3, y), dimstyle=dimstyle,
292                                 override=override)  # type: DimStyleOverride
293        dh = -.7
294        dv = 1.5
295        dim.shift_text(dh, dv)
296        dim.render(ucs=ucs, discard=BRICSCAD)
297        add_text([f'shift text=({dh}, {dv})', ], insert=Vec3(x, y))
298
299        override['dimtix'] = 1  # force text inside
300        x += 4
301        dim = msp.add_linear_dim(base=base, p1=(x, y), p2=(x + .3, y), dimstyle=dimstyle,
302                                 override=override)  # type: DimStyleOverride
303        dh = 0
304        dv = 1
305        dim.shift_text(dh, dv)
306        dim.render(ucs=ucs, discard=BRICSCAD)
307        add_text([f'shift text=({dh}, {dv})', ], insert=Vec3(x, y))
308
309    dimstyles = ['TICK', 'ARCHTICK', 'CLOSEDBLANK']
310    xoffset = 17
311    yoffset = 5
312    for col, dimstyle in enumerate(dimstyles):
313        row = 0
314        for halign in ('center', 'left', 'right'):
315            text(dimstyle, x=col * xoffset, y=row * yoffset, halign=halign, valign='above')
316            row += 1
317            text(dimstyle, x=col * xoffset, y=row * yoffset, halign=halign, valign='center')
318            row += 1
319            text(dimstyle, x=col * xoffset, y=row * yoffset, halign=halign, valign='below')
320            row += 1
321
322        text(dimstyle, x=col * xoffset, y=row * yoffset, halign='above1', valign='above')
323        row += 1
324
325        text(dimstyle, x=col * xoffset, y=row * yoffset, halign='above2', valign='above')
326        row += 1
327
328        user_text_free(dimstyle, x=col * xoffset, y=row * yoffset)
329        row += 1
330
331        user_text_free(dimstyle, x=col * xoffset, y=row * yoffset, leader=True)
332        row += 1
333
334        text(dimstyle, x=col * xoffset, y=row * yoffset, halign='center', valign='above', oblique=70)
335        row += 1
336
337        text(dimstyle, x=col * xoffset, y=row * yoffset, halign='above1', valign='above', oblique=80)
338        row += 1
339
340    doc.saveas(OUTDIR / filename)
341
342
343def example_multi_point_linear_dimension():
344    """
345    Example for using the ezdxf "multi-point linear dimension" feature, which generates dimension entities for multiple
346    points at ones and tries to move dimension text to a readable location.
347
348    This feature works best with DXF R2007+.
349
350    """
351    doc = ezdxf.new('R2007', setup=True)
352    msp = doc.modelspace()
353    points = [(0, 0), (5, 1), (5.2, 1), (5.4, 0), (7, 0), (10, 3)]
354    msp.add_lwpolyline(points)
355
356    # create quick a new DIMSTYLE as alternative to overriding DIMSTYLE attributes
357    dimstyle = doc.dimstyles.duplicate_entry('EZDXF', 'WITHTFILL')  # type: DimStyle
358    dimstyle.dxf.dimtfill = 1
359
360    msp.add_multi_point_linear_dim(base=(0, 5), points=points, dimstyle='WITHTFILL')
361    doc.saveas(OUTDIR / f'multi_point_linear_dim_R2007.dxf')
362
363
364def random_point(start, end):
365    dist = end - start
366    return Vec3(start + random.random() * dist, start + random.random() * dist)
367
368
369def example_random_multi_point_linear_dimension(count=10, length=20, discard=BRICSCAD):
370    """
371    Example for using the ezdxf "multi-point linear dimension" feature, which generates dimension entities for multiple
372    points at ones and tries to move dimension text to a readable location.
373
374    This feature works best with DXF R2007+.
375
376    """
377    doc = ezdxf.new('R2007', setup=True)
378    msp = doc.modelspace()
379
380    # create a random polyline.
381    points = [random_point(0, length) for _ in range(count)]
382    msp.add_lwpolyline(points, dxfattribs={'color': 1})
383
384    # create quick a new DIMSTYLE as alternative to overriding DIMSTYLE attributes
385    dimstyle = doc.dimstyles.duplicate_entry('EZDXF', 'WITHTFILL')  # type: DimStyle
386
387    dimstyle.dxf.dimtfill = 1
388    dimstyle.dxf.dimdec = 2
389
390    dimstyle = doc.dimstyles.duplicate_entry('WITHTFILL', 'WITHTXT')  # type: DimStyle
391    dimstyle.dxf.dimblk = ezdxf.ARROWS.closed
392    dimstyle.dxf.dimtxsty = 'STANDARD'
393    dimstyle.dxf.dimrnd = .5
394    dimstyle.set_text_align(valign='center')
395
396    msp.add_multi_point_linear_dim(base=(0, length + 2), points=points, dimstyle='WITHTFILL', discard=discard)
397    msp.add_multi_point_linear_dim(base=(-2, 0), points=points, angle=90, dimstyle='WITHTFILL', discard=discard)
398    msp.add_multi_point_linear_dim(base=(10, -10), points=points, angle=45, dimstyle='WITHTXT', discard=discard)
399    doc.saveas(OUTDIR / f'multi_random_point_linear_dim_R2007.dxf')
400
401
402def linear_all_arrow_style(version='R12', dimltype=None, dimltex1=None, dimltex2=None, filename=""):
403    """
404    Show all AutoCAD standard arrows on a linear dimension.
405
406    Args:
407        version: DXF version
408        dimltype: dimension linetype
409        dimltex1: linetype for first extension line
410        dimltex2: linetype for second extension line
411        filename: filename for saving
412
413    """
414    doc = ezdxf.new(version, setup=True)
415    msp = doc.modelspace()
416    ezdxf_dimstyle = doc.dimstyles.get('EZDXF')  # type: DimStyle
417    ezdxf_dimstyle.copy_to_header(doc)
418
419    for index, name in enumerate(sorted(ezdxf.ARROWS.__all_arrows__)):
420        y = index * 4
421        attributes = {
422            'dimtxsty': 'LiberationMono',
423            'dimdle': 0.5,
424        }
425        if dimltype:
426            attributes['dimltype'] = dimltype
427        if dimltex1:
428            attributes['dimltex1'] = dimltex1
429        if dimltex2:
430            attributes['dimltex2'] = dimltex2
431
432        dim = msp.add_linear_dim(base=(3, y + 2), p1=(0, y), p2=(3, y), dimstyle='EZDXF',
433                                 override=attributes)  # type: DimStyleOverride
434        dim.set_arrows(blk=name, size=.25)
435        dim.render()
436
437    if not filename:
438        filename = 'all_arrow_styles_dim_{}.dxf'.format(version)
439
440    doc.saveas(OUTDIR / filename)
441
442
443def linear_tutorial_using_tolerances(version='R2000'):
444    """
445    Shows usage of tolerances for the dimension text.
446
447    ezdxf uses MTEXT features for tolerance rendering and therefore requires DXF R2000+, but if you are using a
448    friendly CAD application like BricsCAD, you can let the CAD application do the rendering job, be aware this files
449    are not AutoCAD compatible.
450
451    Args:
452        version: DXF version
453
454    """
455    doc = ezdxf.new(version, setup=True)
456    msp = doc.modelspace()
457
458    # DO NOT RENDER BY EZDXF for DXF R12
459    discard = version == 'R12'
460
461    tol_style = doc.dimstyles.duplicate_entry('EZDXF', 'TOLERANCE')  # type: DimStyle
462    # not all features are supported by DXF R12:
463    # zero suppression (DIMTZIN), align (DIMTOLJ) and dec (DIMTDEC) require DXF R2000+
464    tol_style.set_tolerance(.1, hfactor=.5, align="top", dec=2)
465    msp.add_linear_dim(base=(0, 3), p1=(0, 0), p2=(10, 0), dimstyle='tolerance').render(discard=discard)
466
467    dim = msp.add_linear_dim(base=(0, 3), p1=(15, 0), p2=(15.5, 0), dimstyle='tolerance')
468    # set tolerance attributes by dim style override
469    dim.set_tolerance(.1, .15, hfactor=.4, align="middle", dec=2)
470    dim.render(discard=discard)
471
472    doc.saveas(OUTDIR / f'dimensions_with_tolerance_{version}.dxf')
473
474
475def linear_tutorial_using_limits(version='R2000'):
476    """
477    Shows usage of limits for the dimension text, limits are the lower and upper limit for the measured distance, the
478    measurement itself is not shown.
479
480    ezdxf uses MTEXT features for limits rendering and therefore requires DXF R2000+, but if you are using a
481    friendly CAD application like BricsCAD, you can let the CAD application do the rendering job, be aware this files
482    are not AutoCAD compatible.
483
484    Args:
485        version: DXF version
486
487    """
488    doc = ezdxf.new(version, setup=True)
489    msp = doc.modelspace()
490    # DO NOT RENDER BY EZDXF for DXF R12
491    discard = version == 'R12'
492
493    tol_style = doc.dimstyles.duplicate_entry('EZDXF', 'LIMITS')  # type: DimStyle
494
495    # not all features are supported by DXF R12:
496    # zero suppression (DIMTZIN), align (DIMTOLJ) and dec (DIMTDEC) require DXF R2000+
497    tol_style.set_limits(upper=.1, lower=.1, hfactor=.5, dec=2)
498
499    msp.add_linear_dim(base=(0, 3), p1=(0, 0), p2=(10, 0), dimstyle='limits').render(discard=discard)
500    msp.add_linear_dim(base=(0, 3), p1=(15, 0), p2=(15.5, 0), dimstyle='limits').render(discard=discard)
501    doc.saveas(OUTDIR / f'dimensions_with_limits_{version}.dxf')
502
503
504def linear_tutorial_using_tvp():
505    """
506    For the vertical text alignment `center`, exists an additional DXF feature, to move the dimension text vertical
507    up and down (DIMTVP). Vertical distance dimension line to text center =  text_height * vshift (DIMTVP)
508
509    """
510    doc = ezdxf.new('R2000', setup=True)
511    msp = doc.modelspace()
512    style = doc.dimstyles.duplicate_entry('EZDXF', 'TVP')  # type: DimStyle
513    # shift text upwards
514    style.set_text_align(valign='center', vshift=2.0)
515    msp.add_linear_dim(base=(0, 3), p1=(0, 0), p2=(10, 0), dimstyle='TVP').render()
516    msp.add_linear_dim(base=(0, 3), p1=(15, 0), p2=(15.5, 0), dimstyle='TVP').render()
517
518    style = doc.dimstyles.duplicate_entry('EZDXF', 'TVP2')  # type: DimStyle
519    # shift text downwards
520    style.set_text_align(valign='center', vshift=-2.0)
521    msp.add_linear_dim(base=(0, 7), p1=(0, 5), p2=(10, 5), dimstyle='TVP2').render()
522    msp.add_linear_dim(base=(0, 7), p1=(15, 5), p2=(15.5, 5), dimstyle='TVP2').render()
523
524    doc.saveas(OUTDIR / 'dimensions_with_dimtvp.dxf')
525
526
527def linear_tutorial_ext_lines():
528    doc = ezdxf.new('R12', setup=True)
529    msp = doc.modelspace()
530
531    msp.add_line((0, 0), (3, 0))
532
533    attributes = {
534        'dimexo': 0.5,
535        'dimexe': 0.5,
536        'dimdle': 0.5,
537        'dimblk': ezdxf.ARROWS.none,
538        'dimclrt': 3,
539    }
540    msp.add_linear_dim(base=(3, 2), p1=(0, 0), p2=(3, 0), dimstyle='EZDXF', override=attributes).render()
541
542    attributes = {
543        'dimtad': 4,
544        'dimclrd': 2,
545        'dimclrt': 4,
546    }
547    msp.add_linear_dim(base=(10, 2), p1=(7, 0), p2=(10, 0), angle=-30, dimstyle='EZDXF', override=attributes).render()
548    msp.add_linear_dim(base=(3, 5), p1=(0, 10), p2=(3, 10), dimstyle='EZDXF', override=attributes).render()
549    doc.saveas(OUTDIR / 'dim_linear_R12_ext_lines.dxf')
550
551
552def linear_EZ_M(fmt):
553    doc = ezdxf.new('R12', setup=('linetypes', 'styles'))
554    msp = doc.modelspace()
555    ezdxf.setup_dimstyle(doc, fmt)
556
557    msp.add_line((0, 0), (1, 0))
558    msp.add_linear_dim(base=(0, 1), p1=(0, 0), p2=(1, 0), dimstyle=fmt).render()
559    doc.saveas(OUTDIR / f'dim_linear_R12_{fmt}.dxf')
560
561
562def linear_EZ_CM(fmt):
563    doc = ezdxf.new('R12', setup=('linetypes', 'styles'))
564    msp = doc.modelspace()
565    ezdxf.setup_dimstyle(doc, fmt)
566
567    msp.add_line((0, 0), (100, 0))
568    msp.add_linear_dim(base=(0, 100), p1=(0, 0), p2=(100, 0), dimstyle=fmt).render()
569    doc.saveas(OUTDIR / f'dim_linear_R12_{fmt}.dxf')
570
571
572def linear_EZ_MM(fmt):
573    doc = ezdxf.new('R12', setup=('linetypes', 'styles'))
574    msp = doc.modelspace()
575    ezdxf.setup_dimstyle(doc, fmt)
576
577    msp.add_line((0, 0), (1000, 0))
578    msp.add_linear_dim(base=(0, 1000), p1=(0, 0), p2=(1000, 0), dimstyle=fmt).render()
579    doc.saveas(OUTDIR / f'dim_linear_R12_{fmt}.dxf')
580
581
582ALL = True
583
584if __name__ == '__main__':
585    example_for_all_text_placings_ucs_R12()
586    example_for_all_text_placings_in_space_R12()
587    example_for_all_text_placings_ucs_R2007()
588    example_for_all_text_placings_in_space_R2007()
589
590    if ALL:
591        linear_tutorial('R2007')
592        linear_tutorial_using_tvp()
593        linear_tutorial_using_limits('R2000')
594        linear_tutorial_using_limits('R12')
595        linear_tutorial_using_tolerances('R2000')
596        linear_tutorial_using_tolerances('R12')
597
598        linear_tutorial('R2007')
599        linear_tutorial('R12')
600        example_background_fill('R2007')
601        example_for_all_text_placings_R12()
602        example_for_all_text_placings_R2007()
603
604        example_multi_point_linear_dimension()
605        example_random_multi_point_linear_dimension(count=10, length=20)
606
607        linear_all_arrow_style('R12')
608        linear_all_arrow_style('R12', dimltex1='DOT2', dimltex2='DOT2', filename='dotted_extension_lines_R12.dxf')
609        linear_all_arrow_style('R2000')
610        linear_all_arrow_style('R2007', dimltex1='DOT2', dimltex2='DOT2', filename='dotted_extension_lines_R2007.dxf')
611
612        linear_tutorial_ext_lines()
613
614        linear_EZ_M('EZ_M_100_H25_CM')
615        linear_EZ_M('EZ_M_1_H25_CM')
616
617        linear_EZ_CM('EZ_CM_100_H25_CM')
618        linear_EZ_CM('EZ_CM_1_H25_CM')
619
620        linear_EZ_MM('EZ_MM_100_H25_MM')
621        linear_EZ_MM('EZ_MM_1_H25_MM')
622