Objects Section

The OBJECTS section is the home of all none graphical objects of a DXF document. The OBJECTS section is accessible by the Drawing.objects attribute.

Convenience methods of the Drawing object to create essential structures in the OBJECTS section:

See also

DXF Internals: OBJECTS Section

class ezdxf.sections.objects.ObjectsSection
rootdict

Returns the root DICTIONARY, or as AutoCAD calls it: the named DICTIONARY.

__len__() int

Returns the count of all DXF objects in the OBJECTS section.

__iter__() Iterator[DXFObject]

Returns an iterator of all DXF objects in the OBJECTS section.

__getitem__(index) DXFObject

Get entity at index.

The underlying data structure for storing DXF objects is organized like a standard Python list, therefore index can be any valid list indexing or slicing term, like a single index objects[-1] to get the last entity, or an index slice objects[:10] to get the first 10 or fewer objects as list[DXFObject].

__contains__(entity)

Returns True if entity stored in OBJECTS section.

Parameters:

entityDXFObject or handle as hex string

query(query: str = '*') EntityQuery

Get all DXF objects matching the Entity Query String.

add_dictionary(owner: str = '0', hard_owned: bool = True) Dictionary

Add new Dictionary object.

Parameters:
  • owner – handle to owner as hex string.

  • hard_ownedTrue to treat entries as hard owned.

add_dictionary_with_default(owner='0', default='0', hard_owned: bool = True) DictionaryWithDefault

Add new DictionaryWithDefault object.

Parameters:
  • owner – handle to owner as hex string.

  • default – handle to default entry.

  • hard_ownedTrue to treat entries as hard owned.

add_dictionary_var(owner: str = '0', value: str = '') DictionaryVar

Add a new DictionaryVar object.

Parameters:
  • owner – handle to owner as hex string.

  • value – value as string

add_geodata(owner: str = '0', dxfattribs=None) GeoData

Creates a new GeoData entity and replaces existing ones. The GEODATA entity resides in the OBJECTS section and NOT in the layout entity space, and it is linked to the layout by an extension dictionary located in BLOCK_RECORD of the layout.

The GEODATA entity requires DXF version R2010+. The DXF Reference does not document if other layouts than model space supports geo referencing, so getting/setting geo data may only make sense for the model space layout, but it is also available in paper space layouts.

Parameters:
  • owner – handle to owner as hex string

  • dxfattribs – DXF attributes for GeoData entity

add_image_def(filename: str, size_in_pixel: tuple[int, int], name: str | None = None) ImageDef

Add an image definition to the objects section.

Add an ImageDef entity to the drawing (objects section). filename is the image file name as relative or absolute path and size_in_pixel is the image size in pixel as (x, y) tuple. To avoid dependencies to external packages, ezdxf can not determine the image size by itself. Returns a ImageDef entity which is needed to create an image reference. name is the internal image name, if set to None, name is auto-generated.

Absolute image paths works best for AutoCAD but not really good, you have to update external references manually in AutoCAD, which is not possible in TrueView. If the drawing units differ from 1 meter, you also have to use: set_raster_variables().

Parameters:
  • filename – image file name (absolute path works best for AutoCAD)

  • size_in_pixel – image size in pixel as (x, y) tuple

  • name – image name for internal use, None for using filename as name (best for AutoCAD)

add_placeholder(owner: str = '0') Placeholder

Add a new Placeholder object.

Parameters:

owner – handle to owner as hex string.

add_underlay_def(filename: str, fmt: str = 'pdf', name: str | None = None) UnderlayDefinition

Add an UnderlayDefinition entity to the drawing (OBJECTS section). filename is the underlay file name as relative or absolute path and fmt as string (pdf, dwf, dgn). The underlay definition is required to create an underlay reference.

Parameters:
  • filename – underlay file name

  • fmt – file format as string 'pdf'|'dwf'|'dgn'

  • name – pdf format = page number to display; dgn format = 'default'; dwf: ????

add_xrecord(owner: str = '0') XRecord

Add a new XRecord object.

Parameters:

owner – handle to owner as hex string.

set_raster_variables(frame: int = 0, quality: int = 1, units: str = 'm') None

Set raster variables.

Parameters:
  • frame0 = do not show image frame; 1 = show image frame

  • quality0 = draft; 1 = high

  • units

    units for inserting images. This defines the real world unit for one drawing unit for the purpose of inserting and scaling images with an associated resolution.

    mm

    Millimeter

    cm

    Centimeter

    m

    Meter (ezdxf default)

    km

    Kilometer

    in

    Inch

    ft

    Foot

    yd

    Yard

    mi

    Mile

    none

    None

(internal API), public interface set_raster_variables()

set_wipeout_variables(frame: int = 0) None

Set wipeout variables.

Parameters:

frame0 = do not show image frame; 1 = show image frame

(internal API)