
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/metadata_processing/plot_sequences.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_metadata_processing_plot_sequences.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_metadata_processing_plot_sequences.py:


======================
Working with sequences
======================

This examples illustrates how to work with sequences.

.. GENERATED FROM PYTHON SOURCE LINES 9-40




.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Number of blocks: [(300a, 00f8) Block Type                          CS: 'APERTURE'
    (300a, 00fe) Block Name                          LO: 'Block1'(300a, 00f8) Block Type                          CS: 'APERTURE'
    (300a, 00fe) Block Name                          LO: 'Block2']






|

.. code-block:: Python


    from pydicom.sequence import Sequence
    from pydicom.dataset import Dataset

    # create to toy datasets
    block_ds1 = Dataset()
    block_ds1.BlockType = "APERTURE"
    block_ds1.BlockName = "Block1"

    block_ds2 = Dataset()
    block_ds2.BlockType = "APERTURE"
    block_ds2.BlockName = "Block2"

    beam = Dataset()
    # note that you should add beam data elements like BeamName, etc; these are
    # skipped in this example
    plan_ds = Dataset()
    # starting from scratch since we did not read a file
    plan_ds.BeamSequence = Sequence([beam])
    plan_ds.BeamSequence[0].BlockSequence = Sequence([block_ds1, block_ds2])
    plan_ds.BeamSequence[0].NumberOfBlocks = 2

    beam0 = plan_ds.BeamSequence[0]
    print('Number of blocks: {}'.format(beam0.BlockSequence))

    # create a new data set
    block_ds3 = Dataset()
    # add data elements to it as above and don't forget to update Number of Blocks
    # data element
    beam0.BlockSequence.append(block_ds3)
    del plan_ds.BeamSequence[0].BlockSequence[1]


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 0.001 seconds)


.. _sphx_glr_download_auto_examples_metadata_processing_plot_sequences.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_sequences.ipynb <plot_sequences.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_sequences.py <plot_sequences.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_sequences.zip <plot_sequences.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
