HPGL/2 Converter Add-on
Added in version 1.1.
The 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 Plotter class in the 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 Plotter class.
To use the HPGL2 add-on, the entry point is the ezdxf.addons.hpgl2.api module.
This module contains the public interface of the add-on and should be imported in the
following way:
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
- class ezdxf.addons.hpgl2.api.ColorMode
The color mode controls how color values are assigned to DXF entities
- ACI
Use the pen number as AutoCAD Color Index (ACI) for DXF entities, ignores the RGB color values
- RGB
Use the pen number as AutoCAD Color Index (ACI) but also set the RGB color for DXF entities, RGB color values have always higher priority than the ACI when displaying DXF content.
The Low Level Functions and Classes
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 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:
commands = hpgl2_commands(hpgl2.ENTER_HPGL2_MODE + data)
Recorder
Player
Properties
- class ezdxf.addons.hpgl2.properties.Properties
Consolidated display properties.
- pen_index
pen index as int
- pen_color
pen color as
RGBtuple
- pen_width
pen width in millimeters (float)
- fill_method
FillMethodof filled polygons
- fill_hatch_line_angle
fill hatch line angle in degrees
- fill_hatch_line_spacing
fill hatch line distance in plotter units
- fill_shading_density
fill shading density in percent from 0 to 100.