Tools

DXF Unicode Decoder

The DXF format uses a special form of unicode encoding: “\U+xxxx”.

To avoid a speed penalty such encoded characters are not decoded automatically by the regular loading function:func:ezdxf.readfile, only the recover module does the decoding automatically, because this loading mode is already slow.

This kind of encoding is most likely used only in older DXF versions, because since DXF R2007 the whole DXF file is encoded in utf8 and a special unicode encoding is not necessary.

The ezdxf.has_dxf_unicode() and ezdxf.decode_dxf_unicode() are new support functions to decode unicode characters “\U+xxxx” manually.

New in version 0.14.

ezdxf.has_dxf_unicode(s: str) → bool

Detect if string s contains encoded DXF unicode characters “\U+xxxx”.

ezdxf.decode_dxf_unicode(s: str) → str

Decode DXF unicode characters “\U+xxxx” in string s.

Tools

Some handy tool functions used internally by ezdxf.

ezdxf.int2rgb(value: int) → Tuple[int, int, int]

Split RGB integer value into (r, g, b) tuple.

ezdxf.rgb2int(rgb: Tuple[int, int, int]) → int

Combined integer value from (r, g, b) tuple.

ezdxf.float2transparency(value: float) → int

Returns DXF transparency value as integer in the range from 0 to 255, where 0 is 100% transparent and 255 is opaque.

Parameters

value – transparency value as float in the range from 0 to 1, where 0 is opaque and 1 is 100% transparency.

ezdxf.transparency2float(value: int) → float

Returns transparency value as float from 0 to 1, 0 for no transparency (opaque) and 1 for 100% transparency.

Parameters

value – DXF integer transparency value, 0 for 100% transparency and 255 for opaque

ezdxf.tools.juliandate(date: datetime.datetime) → float
ezdxf.tools.calendardate(juliandate: float) → datetime.datetime
ezdxf.tools.set_flag_state(flags: int, flag: int, state: bool = True) → int

Set/clear binary flag in data flags.

Parameters
  • flags – data value

  • flag – flag to set/clear

  • stateTrue for setting, False for clearing

ezdxf.tools.guid() → str

Returns a general unique ID, based on uuid.uuid1().

ezdxf.tools.bytes_to_hexstr(data: bytes) → str

Returns data bytes as plain hex string.

ezdxf.tools.suppress_zeros(s: str, leading: bool = False, trailing: bool = True)

Suppress trailing and/or leading 0 of string s.

Parameters
  • s – data string

  • leading – suppress leading 0

  • trailing – suppress trailing 0

ezdxf.tools.aci2rgb(index: int) → Tuple[int, int, int]

Convert AutoCAD Color Index (ACI) into (r, g, b) tuple, based on default AutoCAD colors.

ezdxf.tools.normalize_text_angle(angle: float, fix_upside_down=True) → float

Normalizes text angle to the range from 0 to 360 degrees and fixes upside down text angles.

Parameters
  • angle – text angle in degrees

  • fix_upside_down – rotate upside down text angle about 180 degree

SAT Format “Encryption”

ezdxf.tools.crypt.encode(text_lines: Iterable[str]) → Iterable[str]

Encode the Standard ACIS Text (SAT) format by AutoCAD “encryption” algorithm.

ezdxf.tools.crypt.decode(text_lines: Iterable[str]) → Iterable[str]

Decode the Standard ACIS Text (SAT) format “encrypted” by AutoCAD.