Skip to content

Commit

Permalink
add more task related docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mozman committed Mar 22, 2024
1 parent 68ba131 commit 6df4df3
Show file tree
Hide file tree
Showing 9 changed files with 368 additions and 32 deletions.
104 changes: 104 additions & 0 deletions docs/source/tasks/add_blockrefs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
.. _add_blockrefs:

Add Block References
====================

Blocks are collections of DXF entities which can be placed multiple times as block
references in different layouts and other block definitions.
A block reference is represented by the INSERT entity.

Add Block Reference
-------------------

Add a block reference to the modelspace for a block definition "BlockName"::

my_block_ref = msp.add_blockref('BlockName', location, dxfattribs={
'xscale': 1.0,
'yscale': 1.0,
'zscale': 1.0,
'rotation': angle,
})

Non-uniform scaling is supported by CAD applications. The rotations angle is in degrees
(circle=360 degrees).

- :meth:`ezdxf.layouts.BaseLayout.add_blockref`

Add Block Attribute
-------------------

To avoid confusion, it's important to distinguish block attributes (ATTRIB entities)
from DXF attributes. Block attributes are text annotations linked to a block reference.
They have their own location and can be attached to any block reference, even without a
corresponding attribute definition (ATTDEF) in the block layout.

Add a block attribute to :code:`my_block_ref`::

my_attribute = my_block_ref.add_attrib("MY_TAG", "VALUE_STR")
my_attribute.set_placement(location)


- "MY_TAG": a unique identifier or label for the attribute, unique in the context of
the block reference
- "VALUE_STR": the text content displayed by the attribute

Block attributes are a subtype of the TEXT entity. This means they inherit placement and
editing functionalities from the TEXT class.

- :meth:`ezdxf.entities.Insert.add_attrib`
- :meth:`ezdxf.entities.Text.set_placement`


Add Block Attribute from Template
---------------------------------

Block definitions can include pre-defined templates for attributes using ATTDEF entities.
The :meth:`~ezdxf.entities.Insert.add_auto_attribs` method simplifies adding these
attributes to block references. It takes a dictionary argument where:

- Keys: the attribute tags (e.g. "MY_TAG").
- Values: the content for each attribute (e.g. "VALUE_STR").

The :meth:`add_auto_attribs` method automatically attaches attributes (ATTRIB entities)
to the block reference. These attributes inherit relevant DXF properties (layer, color,
text style, etc.) from the corresponding ATTDEF entities within the block definition.

The method also ensures that the relative position of each attribute within the block
reference mirrors the position of its corresponding ATTDEF entity relative to the
block origin::

my_block_ref.add_auto_attrib({"MY_TAG": "VALUE_STR"})


- :meth:`ezdxf.entities.Insert.add_auto_attribs`

.. seealso::

**Tasks:**

- :ref:`add_dxf_entities`
- :ref:`copy_or_move_entities`
- :ref:`delete_dxf_entities`

**Tutorials:**

- :ref:`tut_blocks`
- :ref:`tut_getting_data`
- :ref:`tut_simple_drawings`

**Basics:**

- :ref:`modelspace_concept`
- :ref:`paperspace_concept`
- :ref:`block_concept`

**Classes:**

- :class:`ezdxf.layouts.BlockLayout`
- :class:`ezdxf.entities.BlockRecord`
- :class:`ezdxf.entities.Block`
- :class:`ezdxf.entities.Insert`
- :class:`ezdxf.entities.Attrib`
- :class:`ezdxf.entities.AttDef`
- :class:`ezdxf.entities.Text`

16 changes: 0 additions & 16 deletions docs/source/tasks/add_blocks.rst

This file was deleted.

89 changes: 84 additions & 5 deletions docs/source/tasks/add_custom_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,103 @@
Add Custom and Extended Data
============================

TODO
DXF supports storing custom data through various mechanisms.

Header Variables
----------------

TODO
Custom data can be stored in the HEADER section of a DXF file. Integer values are stored
in variables named $USERI1 to $USERI5, while floating-point values are stored in
variables named $USERR1 to $USERR5.

Example::

doc.header["$USERI1"] = 17

XDATA Section
-------------

TODO
The XDATA section is a container for extended data associated with an entity. It's
essentially a way to store additional information beyond the standard DXF properties for
that particular entity. The XDATA section is divided into sub-sections, each associated
with an AppID.

It's important that the AppID is registered in the AppID table::

doc.appids.add("YOUR_ID")

- :meth:`ezdxf.sections.table.AppIDTable.add`

Example::

point = msp.add_point((10, 10))
point.set_xdata("YOUR_ID", (1040, 3.1415))

- :meth:`ezdxf.entities.DXFEntity.set_xdata`

Extension Dictionaries
----------------------

TODO
Each DXF entity can have an extension dictionary to attach custom data.
The extension dictionary is a :class:`~ezdxf.entities.Dictionary` entity which stores
references to other DXF entities in a key/value storage, mostly :class:`~ezdxf.entities.Dictionary`
and :class:`~ezdxf.entities.XRecord` entities.

Example::

point = msp.add_point((10, 10))
xdict = point.new_extension_dict()

- :meth:`ezdxf.entities.DXFEntity.new_extension_dict`

Custom Data as XRECORD
----------------------

TODO
The XRECORD is used to store arbitrary data. It is composed of DXF group codes ranging
from 1 through 369. This object is similar in concept to XDATA but is not limited by
size or order.

Example::

point = msp.add_point((10, 10))
xdict = point.new_extension_dict()
xrecord = xdict.add_xrecord("MyData")
xrecord.extend([(1, "MyText"), (40, 3.1415)])

- :meth:`ezdxf.entities.xdict.ExtensionDict.add_xrecord`
- :meth:`ezdxf.entities.xdict.ExtensionDict.add_dictionary`
- :meth:`ezdxf.entities.xdict.ExtensionDict.add_dictionary_var`

.. seealso::

**Tasks:**

- :ref:`get_extended_data`
- :ref:`modify_extended_data`
- :ref:`delete_extended_data`

**Tutorials:**

- :ref:`tut_custom_data`

**Basics:**

- :ref:`xdata_internals`
- :ref:`extension_dictionary`
- :ref:`dxf_tags_internals`

**Classes:**

- :class:`ezdxf.entities.xdata.XData`
- :class:`ezdxf.entities.xdict.ExtensionDict`
- :class:`ezdxf.entities.XRecord`
- :class:`ezdxf.entities.Dictionary`
- :class:`ezdxf.entities.DictionaryVar`

**Helper-Classes:**

- :class:`ezdxf.entities.xdata.XDataUserList`
- :class:`ezdxf.entities.xdata.XDataUserDict`
- :class:`ezdxf.urecord.UserRecord`
- :class:`ezdxf.urecord.BinaryRecord`

8 changes: 6 additions & 2 deletions docs/source/tasks/add_layouts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ Add a new paperspace layout to a DXF document::

The layout name is the name shown on the tab in CAD applications and has to be unique,
otherwise a :class:`DXFValueError` will be raised.
See also :meth:`ezdxf.layouts.Layouts.new` method.

It is possible to add multiple paperspace layouts to all DXF versions, but `ezdxf`
exports for DXF R12 only the active paperspace layout. Any paperspace layout can be
set as the active paperspace layout by the method: :meth:`ezdxf.layouts.Layouts.set_active_layout`.

- :meth:`ezdxf.layouts.Layouts.new`

Block Definition
----------------

Expand All @@ -41,7 +42,6 @@ Add a new block definition to a DXF document::
doc.blocks.new("MyLayout")

The block name has to be unique, otherwise a :class:`DXFValueError` will be raised.
See also :meth:`ezdxf.sections.blocks.BlocksSection.new` method.

Add an anonymous block definition::

Expand All @@ -52,6 +52,9 @@ Add an anonymous block definition::
Anonymous blocks are used internally and do not show up in the insert dialog for block
references in CAD applications.

- :meth:`ezdxf.sections.blocks.BlocksSection.new`
- :meth:`ezdxf.sections.blocks.BlocksSection.new_anonymous_block`

.. seealso::

**Tasks:**
Expand All @@ -61,6 +64,7 @@ references in CAD applications.
- :ref:`add_dxf_entities`
- :ref:`copy_or_move_entities`
- :ref:`delete_dxf_entities`
- :ref:`add_blockrefs`

**Tutorials:**

Expand Down
75 changes: 69 additions & 6 deletions docs/source/tasks/add_resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,93 @@
Add Resource Table Entries
==========================

TODO
All resources require a unique name in their category (names are case-insensitive).

Layer
-----

TODO
A layer in a DXF document is a category that controls visual properties (like color and
linetype) for associated entities. It acts like a grouping tag, not a container.

Add a new layer to a DXF document::

doc.layers.add("MY_NEW_LAYER", color=1, linetype="DASHED")

DXF entities reference layers, but layers themselves don't directly contain entities.
Instead, each entity has a :attr:`dxf.layer` attribute that specifies the layer by name
it belongs to.

- :meth:`ezdxf.sections.table.LayerTable.add`

Linetype
--------

TODO
The linetype defines the rendering pattern of linear graphical entities like LINE, ARC,
CIRCLE and so on.

Add a new linetype to a DXF document::

doc.linetypes.add("DOTTED", pattern=[0.2, 0.0, -0.2])

- :meth:`ezdxf.sections.table.LinetypeTable.add`

Text Style
----------

TODO
The text style defines the rendering font for text based entities like TEXT, ATTRIB and
MTEXT.

Add a new text style to a DXF document::

doc.styles.add("ARIAL", font="arial.ttf")

- :meth:`ezdxf.sections.table.TextstyleTable.add`

Dimension Style
---------------

TODO
The dimension style defines the initial properties for the DIMENSION entity.

Add a new dimension style to a DXF document::

doc.dimstyles.add("EZDXF")

- :meth:`ezdxf.sections.table.DimStyleTable.add`

AppID
-----

TODO
The XDATA section of DXF entities is grouped by AppIDs and these ids require an entry in
the :class:`AppIDTable` otherwise the DXF file in invalid (for AutoCAD)::

doc.appids.add("EZDXF")

- :meth:`ezdxf.sections.table.AppIDTable.add`

.. seealso::

**Tutorials:**

- :ref:`tut_layers`
- :ref:`tut_linetypes`
- :ref:`tut_text`
- :ref:`tut_mtext`
- :ref:`tut_common_graphical_attributes`

**Basics:**

- :ref:`layer_concept`
- :ref:`linetypes`
- :ref:`lineweights`
- :ref:`aci`
- :ref:`true color`
- :ref:`font resources`

**Classes:**

- :class:`ezdxf.entities.Layer`
- :class:`ezdxf.entities.Linetype`
- :class:`ezdxf.entities.Textstyle`
- :class:`ezdxf.entities.DimStyle`
- :class:`ezdxf.entities.Appid`
- :mod:`ezdxf.fonts.fonts`
Loading

0 comments on commit 6df4df3

Please sign in to comment.