File: hpgl2.rst

package info (click to toggle)
ezdxf 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104,528 kB
  • sloc: python: 182,341; makefile: 116; lisp: 20; ansic: 4
file content (253 lines) | stat: -rw-r--r-- 6,777 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
.. module:: ezdxf.addons.hpgl2.api

HPGL/2 Converter Add-on
=======================

.. versionadded:: 1.1

The :mod:`hpgl2` add-on provides tools to process and convert HPGL/2 plot files.

What are HPGL/2 Plot Files?
---------------------------

The Hewlett-Packard Graphics Language (HPGL) is a vector graphics language originally
developed by Hewlett-Packard in the 1970s. HPGL is widely used for controlling pen
plotters and other output devices, and it has become a de facto standard for
communicating between computers and output devices in the field of computer-aided design
(CAD) and drafting.

HPGL is a command-driven language that consists of a series of commands that control the
movement of the plotter pen, the selection of pens and other output parameters, and the
drawing of geometric shapes such as lines, arcs, circles, and text. The language is
interpreted by the plotter or other output device and translated into physical pen
movements on the drawing surface.

HPGL has evolved over the years, and various extensions have been added to support more
complex graphics operations and to improve compatibility with other graphics languages.
Despite the development of newer graphics languages and file formats, HPGL remains a
widely used format for vector-based graphics, particularly in the engineering and
architectural fields.

The Goal of This Add-on
-----------------------

An HPGL/2 plot file contains all of the data generated by a CAD application that has been
sent to a plotter to print an engineering drawing. In the past, the only way to access
this data was to view it on a plotter or an specialized application, which could be
expensive and impractical for many people. However, this module provides functions and
classes to convert HPGL/2 plot files into modern vector graphic formats such as `PDF`_
and `SVG`_ and of course DXF, allowing the data to be viewed and processed using a wide
range of software tools.

.. Important::

    The Python module PyMuPDF is required for the PDF export: https://pypi.org/project/PyMuPDF/

The :class:`Plotter` class in the :mod:`hpgl2` add-on supports only the most commonly
used commands of HPGL/2. This is because many CAD applications use only a small subset
of HPGL/2 to create their output, typically consisting of polylines and filled polygons.
For more information on the supported commands, please refer to the documentation for
the :class:`Plotter` class.

To use the HPGL2 add-on, the entry point is the :mod:`ezdxf.addons.hpgl2.api` module.
This module contains the public interface of the add-on and should be imported in the
following way:


.. code-block:: Python

    from ezdxf.addons.hpgl2 import api as hpgl2

    with open("hpgl2.plt", "rb") as fp:
        data = fp.read()
    doc = hpgl2.to_dxf(data, color_mode=hpgl2.ColorMode.ACI)
    doc.saveas("hpgl2_as.dxf")


High Level Functions
--------------------

.. autosummary::
    :nosignatures:

    to_dxf
    to_svg
    to_pdf
    to_pixmap

.. autofunction:: to_dxf

.. autofunction:: to_svg

.. autofunction:: to_pdf

.. autofunction:: to_pixmap

.. class:: ColorMode

    The color mode controls how color values are assigned to DXF entities

    .. attribute:: ACI

        Use the pen number as :ref:`ACI` for DXF entities, ignores the RGB color values

    .. attribute:: RGB

        Use the pen number as :ref:`ACI` but also set the RGB color for DXF entities,
        RGB color values have always higher priority than the ACI when displaying DXF
        content.

.. class:: MergeControl

    Merge control enumeration.

    .. attribute:: NONE

        export filled polygons in print order

    .. attribute:: LUMINANCE

        sort filled polygons by luminance

    .. attribute:: AUTO

        guess best order of filled polygons

The Low Level Functions and Classes
-----------------------------------

.. autofunction:: hpgl2_commands

The HPGL/2 commands are often mixed with the Printer Command Language (`PCL`_) and/or the
Raster Transfer Language (`RTL`_) commands in a single plot file.

Some plot files that contain pure HPGL/2 code do not contain the escape sequence
"Enter HPGL/2 mode", without this sequence the HPGL/2 parser cannot recognize the
beginning of the HPGL/2 code. Add the :attr:`ENTER_HPGL2_MODE` sequence in front of the
bytes stream to switch on the HPGL/2 manually, regardless of whether the file is an
HPGL/2 plot file or not, so be careful:

.. code-block:: Python

    commands = hpgl2_commands(hpgl2.ENTER_HPGL2_MODE + data)


.. autoclass:: Interpreter

    .. attribute:: errors

        List of error messages occurred during the interpretation of the HPGL/2 commands.

    .. attribute:: not_implemented_commands

        List of all unsupported/ignored commands from the input stream.

    .. automethod:: run

    .. automethod:: disable_commands

.. autoclass:: Plotter

Recorder
--------

.. autoclass:: Recorder

    .. automethod:: player

    .. automethod:: draw_polyline

    .. automethod:: draw_paths

Player
------

.. autoclass:: Player

    .. automethod:: copy

    .. automethod:: recordings

    .. automethod:: replay

    .. automethod:: bbox

    .. automethod:: transform

    .. automethod:: sort_filled_paths

Properties
----------

.. autoclass:: ezdxf.addons.hpgl2.properties.Properties

    .. attribute:: pen_index

        pen index as int

    .. attribute:: pen_color

        pen color as :class:`RGB` tuple

    .. attribute:: pen_width

        pen width in millimeters (float)

    .. attribute:: fill_type

        :class:`FillType` of filled polygons

    .. attribute:: fill_method

        :class:`FillMethod` of filled polygons

    .. attribute:: fill_hatch_line_angle

        fill hatch line angle in degrees

    .. attribute:: fill_hatch_line_spacing

        fill hatch line distance in plotter units

    .. attribute:: fill_shading_density

        fill shading density in percent from 0 to 100.

    .. automethod:: resolve_pen_color

    .. automethod:: resolve_fill_color

.. autoclass:: ezdxf.addons.hpgl2.properties.FillType

    .. attribute:: NONE

    .. attribute:: SOLID

    .. attribute:: HATCHING

    .. attribute:: CROSS_HATCHING

    .. attribute:: SHADING

.. autoclass:: ezdxf.addons.hpgl2.properties.FillMethod

    .. attribute:: EVEN_ODD

    .. attribute:: NONE_ZERO_WINDING

Exceptions
-----------

.. autoclass:: Hpgl2Error

.. autoclass:: Hpgl2DataNotFound

.. autoclass:: EmptyDrawing


.. _PyMuPDF: https://pypi.org/project/PyMuPDF/
.. _HPGL/2: https://en.wikipedia.org/wiki/HP-GL
.. _PCL: https://en.wikipedia.org/wiki/Printer_Command_Language
.. _RTL: https://en.wikipedia.org/wiki/Hewlett-Packard_Raster_Transfer_Language
.. _SVG: https://en.wikipedia.org/wiki/SVG
.. _PDF: https://en.wikipedia.org/wiki/PDF