### Example installation output Source: https://ezdxf.readthedocs.io/en/stable/setup.html Expected output after running the verification command. ```text ezdxf 0.17.2b4 from /home/pi/src/.venv/lib/python3.7/site-packages/ezdxf Python version: 3.7.3 (default, Jan 22 2021, 20:04:44) [GCC 8.3.0] using C-extensions: yes using Matplotlib: yes ``` -------------------------------- ### Verify Installation Output Source: https://ezdxf.readthedocs.io/en/stable/setup.html Example output confirming successful installation and C-extension status. ```text ezdxf 0.17.2b4 from D:\Source\build\.venv\lib\site-packages\ezdxf Python version: 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] using C-extensions: yes using Matplotlib: no ``` -------------------------------- ### Verify Installation Output on Linux Source: https://ezdxf.readthedocs.io/en/stable/setup.html Example output confirming successful installation on Linux. ```text ezdxf 0.17.2b4 from /home/mozman/src/.venv/lib/python3.8/site-packages/ezdxf Python version: 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0] using C-extensions: yes using Matplotlib: no ``` -------------------------------- ### Tutorial Prolog Constants Source: https://ezdxf.readthedocs.io/en/stable/tutorials/mtext.html Common setup for MTextEditor examples. ```python # use constants defined in MTextEditor: NP = MTextEditor.NEW_PARAGRAPH ATTRIBS = { "char_height": 0.7, "style": "OpenSans", "width": 10, } editor = MTextEditor("using colors:" + NP) ``` -------------------------------- ### Initialize DXF Document and Layout Source: https://ezdxf.readthedocs.io/en/stable/tutorials/dxf_primitives.html Setup code required for all subsequent entity examples, including document creation and layer configuration. ```python import ezdxf from ezdxf.gfxattribs import GfxAttribs doc = ezdxf.new() doc.layers.new("ENTITY", color=1) msp = doc.modelspace() attribs = GfxAttribs(layer="ENTITY") ``` -------------------------------- ### Install build tools Source: https://ezdxf.readthedocs.io/en/stable/setup.html Install Cython and wheel to facilitate the compilation of C-extensions. ```bash pip3 install cython wheel ``` -------------------------------- ### Build and Install from Source on Windows Source: https://ezdxf.readthedocs.io/en/stable/setup.html Steps to set up a virtual environment, install build dependencies, and compile ezdxf with C-extensions on Windows. ```bash mkdir build cd build py -m venv .venv .venv/Scripts/activate.bat ``` ```bash pip3 install setuptools wheel cython ``` ```bash git clone https://github.com/mozman/ezdxf.git ``` ```bash cd ezdxf pip3 install . ``` ```bash python3 -m ezdxf -V ``` -------------------------------- ### Install PyQt5 on Ubuntu Server Source: https://ezdxf.readthedocs.io/en/stable/setup.html Install PyQt5 bindings via the system package manager. ```bash sudo apt install python3-pyqt5 ``` -------------------------------- ### Build and Install from Source on WSL/Ubuntu Source: https://ezdxf.readthedocs.io/en/stable/setup.html Steps to install system dependencies, set up a virtual environment, and compile ezdxf on Linux-based systems. ```bash sudo apt install build-essential python3.10-dev ``` ```bash cd ~ mkdir build cd build python3 -m venv .venv source .venv/bin/activate ``` ```bash pip3 install cython wheel ``` ```bash git clone https://github.com/mozman/ezdxf.git ``` ```bash cd ezdxf pip3 install . ``` ```bash python3 -m ezdxf -V ``` -------------------------------- ### Clone and install ezdxf Source: https://ezdxf.readthedocs.io/en/stable/setup.html Download the source code from GitHub and install the package. ```bash git clone https://github.com/mozman/ezdxf.git cd ezdxf pip3 install . ``` -------------------------------- ### Initialize ExampleCls Source: https://ezdxf.readthedocs.io/en/stable/develop/doc_formatting_guide.html Example of instantiating the ExampleCls class with a keyword argument. ```python e = ExampleCls(flag=True) ``` -------------------------------- ### Install ezdxf on Manjaro Source: https://ezdxf.readthedocs.io/en/stable/setup.html Complete the installation process on Manjaro after setting up the virtual environment. ```bash pip3 install cython wheel git clone https://github.com/mozman/ezdxf.git cd ezdxf pip3 install . python3 -m ezdxf -V ``` -------------------------------- ### Setup imports and constants Source: https://ezdxf.readthedocs.io/en/stable/tutorials/xref_module.html Required imports and DXF version constant for the tutorial. ```python import ezdxf from ezdxf.addons import odafc from ezdxf.document import Drawing from ezdxf import xref, units, colors from ezdxf.render import forms DXFVERSION = "R2013" ``` -------------------------------- ### Build and Install Python Source: https://ezdxf.readthedocs.io/en/stable/setup.html Compile the source code using parallel jobs and install the interpreter. ```bash make -j 4 sudo make install ``` -------------------------------- ### Build Documentation Source: https://ezdxf.readthedocs.io/en/stable/setup.html Install Sphinx and generate HTML documentation from the docs directory. ```bash pip3 install Sphinx sphinx-rtd-theme ``` ```bash cd docs make html ``` -------------------------------- ### Install Sphinx Read the Docs Theme Source: https://ezdxf.readthedocs.io/en/stable/develop/doc_formatting_guide.html Command to install the required Sphinx theme for documentation rendering. ```bash pip install sphinx-rtd-theme ``` -------------------------------- ### Verify ezdxf installation Source: https://ezdxf.readthedocs.io/en/stable/setup.html Check the installed version and configuration of ezdxf. ```bash python3 -m ezdxf -V ``` -------------------------------- ### guide.ExampleCls Source: https://ezdxf.readthedocs.io/en/stable/develop/doc_formatting_guide.html A class representing an example object with configurable attributes and methods. ```APIDOC ## class guide.ExampleCls(**kwargs) ### Description Constructor for ExampleCls, accepting optional keyword arguments that map to instance attributes. ### Methods - **set_axis(axis)**: Sets the axis using an (x, y, z) tuple. - **example_method(flag=False)**: An example method that accepts a boolean flag. ``` -------------------------------- ### Install build requirements on Raspberry Pi OS Source: https://ezdxf.readthedocs.io/en/stable/setup.html Install Matplotlib and PyQt5 bindings using the system package manager. ```bash sudo apt install python3-pip python3-matplotlib python3-pyqt5 ``` -------------------------------- ### Setup predefined linetypes Source: https://ezdxf.readthedocs.io/en/stable/tutorials/linetypes.html Iterate through standard linetypes and add them to the document. ```python for name, desc, pattern in linetypes(): if name not in doc.linetypes: doc.linetypes.add( name=name, pattern= pattern, description=desc, ) ``` -------------------------------- ### Install build requirements on Ubuntu Server Source: https://ezdxf.readthedocs.io/en/stable/setup.html Install essential build tools and Python venv module. ```bash sudo apt install build-essential python3-pip python3.9-venv ``` -------------------------------- ### Install ezdxf with drawing extras Source: https://ezdxf.readthedocs.io/en/stable/setup.html Installs ezdxf along with additional packages required for drawing functionality. ```bash pip3 install ezdxf[draw] ``` -------------------------------- ### Install Development Version from GitHub Source: https://ezdxf.readthedocs.io/en/stable/setup.html Install the latest master branch directly from the GitHub repository using pip. ```bash pip3 install git+https://github.com/mozman/ezdxf.git@master ``` -------------------------------- ### Install Optional Packages Source: https://ezdxf.readthedocs.io/en/stable/setup.html Install matplotlib and PySide6 dependencies via pip on supported systems. ```bash pip3 install matplotlib PySide6 ``` -------------------------------- ### Install ezdxf via pip Source: https://ezdxf.readthedocs.io/en/stable/setup.html Standard command to install the core ezdxf package and its hard dependencies. ```bash pip3 install ezdxf ``` -------------------------------- ### Create Virtual Environment with Custom Python Source: https://ezdxf.readthedocs.io/en/stable/setup.html Initialize a virtual environment using the newly installed Python interpreter. ```bash cd ~/build /opt/python3.9.9/bin/python3 -m venv py39 source py39/bin/activate ``` -------------------------------- ### ezdxf.addons.odafc.is_installed() Source: https://ezdxf.readthedocs.io/en/stable/addons/odafc.html Checks if the ODA File Converter is correctly installed and accessible. ```APIDOC ## is_installed() ### Description Returns a boolean indicating whether the ODAFileConverter is installed and available for use. ### Returns - **bool** - True if installed, False otherwise. ``` -------------------------------- ### Install Black formatter Source: https://ezdxf.readthedocs.io/en/stable/addons/dxf2code.html Command to install the Black formatter required for the black() function and black_code_str() method. ```bash pip3 install black ``` -------------------------------- ### Run Tests Source: https://ezdxf.readthedocs.io/en/stable/setup.html Install pytest and execute the test suite within the build directory. ```bash pip3 install pytest python3 -m pytest tests integration_tests ``` -------------------------------- ### Configure Frontend Rendering Source: https://ezdxf.readthedocs.io/en/stable/tutorials/image_export.html Example of overriding default rendering settings by creating a Configuration object and passing it to the Frontend. ```python # 2. create the backend backend = svg.SVGBackend() # create a new configuration for a white background and and a black foreground color cfg = config.Configuration( background_policy=config.BackgroundPolicy.WHITE, color_policy=config.ColorPolicy.BLACK, ) # 3. create the frontend frontend = Frontend(context, backend, config=cfg) ``` -------------------------------- ### AutoLISP Script Output Source: https://ezdxf.readthedocs.io/en/stable/tutorials/custom_data.html Example output from the SHOWXDATA command. ```text : SHOWXDATA Select entity: ("YOUR_UNIQUE_ID" (1000 . "custom text") (1040 . 3.141592) ... ``` -------------------------------- ### Configure Python Build Source: https://ezdxf.readthedocs.io/en/stable/setup.html Configure the build process with a specific installation prefix and optimizations. ```bash ./configure --prefix=/opt/python3.9.9 --enable-optimizations ``` -------------------------------- ### Cache Statistics Output Source: https://ezdxf.readthedocs.io/en/stable/bbox.html Example output showing cache hits and misses. ```text Cache(n=1226, hits=0, misses=3273) ``` ```text Cache(n=2206, hits=0, misses=3273) ``` -------------------------------- ### Browse DXF File Structure Source: https://ezdxf.readthedocs.io/en/stable/howto/document.html Launches the DXF structure browser to visualize entities. Requires PySide6 or PyQt5 to be installed. ```bash # Call as executable script from the command line: ezdxf browse FILE # Call as module on Windows: py -m ezdxf browse FILE # Call as module on Linux/Mac python3 -m ezdxf browse FILE ``` -------------------------------- ### Initialize ezdxf Document Source: https://ezdxf.readthedocs.io/en/stable/tutorials/mtext.html Setup a new DXF R2007 document and define a multi-line string for MText content. ```python import ezdxf doc = ezdxf.new("R2007", setup=True) msp = doc.modelspace() lorem_ipsum = """ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. """ ``` -------------------------------- ### Configure ODAFC Add-on Paths Source: https://ezdxf.readthedocs.io/en/stable/addons/odafc.html Example configuration for the [odafc-addon] section, specifying absolute paths for Windows and Linux executables. ```ini [odafc-addon] win_exec_path = "C:\Program Files\ODA\ODAFileConverter\ODAFileConverter.exe" unix_exec_path = "/home//Apps/ODAFileConverter_QT5_lnxX64_8.3dll_23.9.AppImage" ``` -------------------------------- ### Configuration File Structure Source: https://ezdxf.readthedocs.io/en/stable/options.html Example of an INI configuration file structure used by ezdxf to manage settings. ```ini [core] default_dimension_text_style = OpenSansCondensed-Light test_files = D:\Source\dxftest support_dirs = "C:\Program Files\Bricsys\BricsCAD V23 en_US\Fonts", "~/dir2", "~/dir3" load_proxy_graphics = true store_proxy_graphics = true log_unprocessed_tags = false filter_invalid_xdata_group_codes = true write_fixed_meta_data_for_testing = false disable_c_ext = false [browse-command] text_editor = "C:\Program Files\Notepad++\notepad++.exe" "{filename}" -n{num} ``` -------------------------------- ### Initialize document with standard styles Source: https://ezdxf.readthedocs.io/en/stable/tutorials/text.html Use the setup=True argument when creating a new document to automatically generate standard text styles and linetypes. ```python doc = ezdxf.new('R12', setup=True) ``` -------------------------------- ### Check ezdxf system information Source: https://ezdxf.readthedocs.io/en/stable/launcher.html Displays the installed ezdxf version, Python version, and C-extension status. ```bash ezdxf 1.1.0b1 from c:\source\ezdxf.git\src\ezdxf Python version: 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] using C-extensions: yes ``` -------------------------------- ### DXF R12 File Structure Example Source: https://ezdxf.readthedocs.io/en/stable/dxfinternals/filestructure.html A template showing the sequential organization of sections and tags in a standard DXF R12 file. ```text 0 <<< Begin HEADER section, has to be the first section SECTION 2 HEADER <<< Header variable items go here 0 <<< End HEADER section ENDSEC 0 <<< Begin TABLES section SECTION 2 TABLES 0 TABLE 2 VPORT 70 <<< viewport table maximum item count <<< viewport table items go here 0 ENDTAB 0 TABLE 2 APPID, DIMSTYLE, LTYPE, LAYER, STYLE, UCS, VIEW, or VPORT 70 <<< Table maximum item count, a not reliable value and ignored by AutoCAD <<< Table items go here 0 ENDTAB 0 <<< End TABLES section ENDSEC 0 <<< Begin BLOCKS section SECTION 2 BLOCKS <<< Block definition entities go here 0 <<< End BLOCKS section ENDSEC 0 <<< Begin ENTITIES section SECTION 2 ENTITIES <<< Drawing entities go here 0 <<< End ENTITIES section ENDSEC 0 <<< End of file marker (required) EOF ``` -------------------------------- ### Linked Column MTEXT Entities Source: https://ezdxf.readthedocs.io/en/stable/dxfinternals/entities/mtext.html Examples of linked MTEXT entities representing individual columns in an R2000 dynamic column setup. ```text 0 MTEXT ... 100 AcDbMText 10 (-71.214579865783, 276.101821192053, 0.0) 40 2.5 41 175.0 <<< invalid column width ... 1001 ACAD 1000 ACAD_MTEXT_DEFINED_HEIGHT_BEGIN 1070 46 <<< defined column height 1040 158.189308131867 1000 ACAD_MTEXT_DEFINED_HEIGHT_END ``` ```text 0 MTEXT ... 100 AcDbMText 10 (-8.714579865783, 276.101821192053, 0.0) 40 2.5 41 175.0 <<< invalid column width ... 1001 ACAD 1000 ACAD_MTEXT_DEFINED_HEIGHT_BEGIN 1070 46 <<< defined column height 1040 158.189308131867 1000 ACAD_MTEXT_DEFINED_HEIGHT_END ``` -------------------------------- ### DXF R2000+ VPORT Table Structure Source: https://ezdxf.readthedocs.io/en/stable/dxfinternals/tables/vport_table.html Example of a VPORT table definition in DXF R2000+ format, showing the table start, entry records, and various group codes for viewport properties. ```text 0 <<< table start TABLE 2 <<< table type VPORT 5 <<< table handle 151F 330 <<< owner, table has no owner - always #0 0 100 <<< subclass marker AcDbSymbolTable 70 <<< VPORT table (max.) count, not reliable (ignore) 3 0 <<< first VPORT entry VPORT 5 <<< entry handle 158B 330 <<< owner, VPORT table is owner of VPORT entry 151F 100 <<< subclass marker AcDbSymbolTableRecord 100 <<< subclass marker AcDbViewportTableRecord 2 <<< VPORT (configuration) name *ACTIVE 70 <<< standard flags, bit-coded 0 10 <<< lower-left corner of viewport 0.45 <<< x value, virtual coordinates in range [0 - 1] 20 <<< group code for y value 0.0 <<< y value, virtual coordinates in range [0 - 1] 11 <<< upper-right corner of viewport 1.0 <<< x value, virtual coordinates in range [0 - 1] 21 <<< group code for y value 1.0 <<< y value, virtual coordinates in range [0 - 1] 12 <<< view center point (in DCS) 13.71 <<< x value 22 <<< group code for y value 0.38 <<< y value 13 <<< snap base point (in DCS) 0.0 <<< x value 23 <<< group code for y value 0.0 <<< y value 14 <<< snap spacing X and Y 1.0 <<< x value 24 <<< group code for y value 1.0 <<< y value 15 <<< grid spacing X and Y 0.0 <<< x value 25 <<< group code for y value 0.0 <<< y value 16 <<< view direction from target point (in WCS) 1.0 <<< x value 26 <<< group code for y value -1.0 <<< y value 36 <<< group code for z value 1.0 <<< z value 17 <<< view target point (in WCS) 0.0 <<< x value 27 <<< group code for y value 0.0 <<< y value 37 <<< group code for z value 0.0 <<< z value 40 <<< view height 35.22 41 <<< viewport aspect ratio 0.99 42 <<< lens (focal) length 50.0 <<< 50mm 43 <<< front clipping planes, offsets from target point 0.0 44 <<< back clipping planes, offsets from target point 0.0 50 <<< snap rotation angle 0.0 51 <<< view twist angle 0.0 71 <<< view mode 0 72 <<< circle zoom percent 1000 73 <<< fast zoom setting 1 74 <<< UCSICON setting 3 75 <<< snap on/off 0 76 <<< grid on/off 0 77 <<< snap style 0 78 <<< snap isopair 0 281 <<< render mode 1-6 (... too many options) 0 <<< 0 = 2D optimized (classic 2D) 65 <<< Value of UCSVP for this viewport. (0 = UCS will not change when this viewport is activated) 1 <<< 1 = then viewport stores its own UCS which will become the current UCS whenever the viewport is activated. 110 <<< UCS origin (3D point) 0.0 <<< x value 120 <<< group code for y value 0.0 <<< y value 130 <<< group code for z value 0.0 <<< z value 111 <<< UCS X-axis (3D vector) 1.0 <<< x value 121 <<< group code for y value 0.0 <<< y value 131 <<< group code for z value 0.0 <<< z value 112 <<< UCS Y-axis (3D vector) 0.0 <<< x value 122 <<< group code for y value 1.0 <<< y value 132 <<< group code for z value 0.0 <<< z value 79 <<< Orthographic type of UCS 0-6 (... too many options) 0 <<< 0 = UCS is not orthographic 146 <<< elevation 0.0 1001 <<< extended data - undocumented ACAD_NAV_VCDISPLAY 1070 3 0 <<< next VPORT entry VPORT 5 158C 330 151F 100 AcDbSymbolTableRecord 100 AcDbViewportTableRecord 2 <<< VPORT (configuration) name *ACTIVE <<< same as first VPORT entry 70 0 10 0.0 20 0.5 11 0.45 21 1.0 12 8.21 22 9.72 ... ... 0 <<< next VPORT entry VPORT 5 158D 330 151F 100 AcDbSymbolTableRecord 100 AcDbViewportTableRecord 2 <<< VPORT (configuration) name *ACTIVE <<< same as first VPORT entry 70 0 10 0.0 20 0.0 11 0.45 21 0.5 12 2.01 22 -8.97 ... ... 0 ENDTAB ``` -------------------------------- ### Modify and save custom configuration Source: https://ezdxf.readthedocs.io/en/stable/options.html Example of updating the test_files path and saving the configuration to a custom file. ```python import ezdxf test_files = Path("~/my-dxf-test-files").expand_user() ezdxf.options.set( ezdxf.options.CORE, # section "test_files", # key "~/my-dxf-test-files", # value ) ezdxf.options.write_file("my_config.ini") ``` -------------------------------- ### Install build requirements on Manjaro Source: https://ezdxf.readthedocs.io/en/stable/setup.html Install dependencies using the pacman package manager. ```bash sudo pacman -S python-pip python-matplotlib python-pyqt5 ``` -------------------------------- ### Fix PySide6 xcb issue Source: https://ezdxf.readthedocs.io/en/stable/setup.html Command to install the missing library required for Qt platform plugin support on Debian-based distributions. ```bash sudo apt-get install libxcb-cursor0 ``` -------------------------------- ### Pack items into bins and export to DXF Source: https://ezdxf.readthedocs.io/en/stable/addons/binpacking.html This example demonstrates how to define bins and items, use the Packer to arrange them, and export the layout to a DXF file. ```python from typing import List import ezdxf from ezdxf import colors from ezdxf.addons import binpacking as bp SMALL_ENVELOPE = ("small-envelope", 11.5, 6.125, 0.25, 10) LARGE_ENVELOPE = ("large-envelope", 15.0, 12.0, 0.75, 15) SMALL_BOX = ("small-box", 8.625, 5.375, 1.625, 70.0) MEDIUM_BOX = ("medium-box", 11.0, 8.5, 5.5, 70.0) MEDIUM_BOX2 = ("medium-box-2", 13.625, 11.875, 3.375, 70.0) LARGE_BOX = ("large-box", 12.0, 12.0, 5.5, 70.0) LARGE_BOX2 = ("large-box-2", 23.6875, 11.75, 3.0, 70.0) ALL_BINS = [ SMALL_ENVELOPE, LARGE_ENVELOPE, SMALL_BOX, MEDIUM_BOX, MEDIUM_BOX2, LARGE_BOX, LARGE_BOX2, ] def build_packer(): packer = bp.Packer() packer.add_item("50g [powder 1]", 3.9370, 1.9685, 1.9685, 1) packer.add_item("50g [powder 2]", 3.9370, 1.9685, 1.9685, 2) packer.add_item("50g [powder 3]", 3.9370, 1.9685, 1.9685, 3) packer.add_item("250g [powder 4]", 7.8740, 3.9370, 1.9685, 4) packer.add_item("250g [powder 5]", 7.8740, 3.9370, 1.9685, 5) packer.add_item("250g [powder 6]", 7.8740, 3.9370, 1.9685, 6) packer.add_item("250g [powder 7]", 7.8740, 3.9370, 1.9685, 7) packer.add_item("250g [powder 8]", 7.8740, 3.9370, 1.9685, 8) packer.add_item("250g [powder 9]", 7.8740, 3.9370, 1.9685, 9) return packer def make_doc(): doc = ezdxf.new() doc.layers.add("FRAME", color=colors.YELLOW) doc.layers.add("ITEMS") doc.layers.add("TEXT") return doc def main(filename): bins: List[bp.Bin] = [] for box in ALL_BINS: packer = build_packer() packer.add_bin(*box) packer.pack(bp.PickStrategy.BIGGER_FIRST) bins.extend(packer.bins) doc = make_doc() bp.export_dxf(doc.modelspace(), bins, offset=(0, 20, 0)) doc.saveas(filename) if __name__ == "__main__": main("py3dbp_example.dxf") ``` -------------------------------- ### guide.example_func Source: https://ezdxf.readthedocs.io/en/stable/develop/doc_formatting_guide.html A function that accepts positional and optional keyword arguments. ```APIDOC ## guide.example_func(a, b, test=None, flag=True) ### Description Performs an operation using positional arguments a and b, with optional test and flag parameters. ### Parameters - **a** (int) - Required - Positional argument. - **b** (str) - Required - Positional argument. - **test** (str) - Optional - Defaults to None. - **flag** (bool) - Optional - Defaults to True. ``` -------------------------------- ### Setup ezdxf resources in an existing document Source: https://ezdxf.readthedocs.io/en/stable/tutorials/angular_dimension.html Use setup_drawing to add necessary line types, text styles, and dimension styles to a loaded DXF file. ```python import ezdxf from ezdxf.tools.standards import setup_drawing doc = ezdxf.readfile("your.dxf") setup_drawing(doc, topics="all") ``` -------------------------------- ### Initialize DXF Document and MLeaderStyle Source: https://ezdxf.readthedocs.io/en/stable/tutorials/mleader.html Sets up a new DXF document and duplicates the Standard MLeaderStyle for custom configuration. ```python doc = ezdxf.new(setup=True) # Create a new custom MLEADERSTYLE: mleaderstyle = doc.mleader_styles.duplicate_entry("Standard", "EZDXF") # The required TEXT style "OpenSans" was created by ezdxf.new() because setup is True: mleaderstyle.set_mtext_style("OpenSans") msp = doc.modelspace() ``` -------------------------------- ### Create Build Directory Source: https://ezdxf.readthedocs.io/en/stable/setup.html Prepare a directory for downloading and compiling Python source code. ```bash cd ~ mkdir build cd build ``` -------------------------------- ### Create and activate virtual environment Source: https://ezdxf.readthedocs.io/en/stable/setup.html Initialize a virtual environment with access to system site-packages to utilize pre-installed libraries. ```bash cd ~ mkdir build cd build python3 -m venv --system-site-packages .venv source .venv/bin/activate ``` -------------------------------- ### Initialize host document Source: https://ezdxf.readthedocs.io/en/stable/tutorials/xref_module.html Create a new host document for attaching the XREF. ```python host_doc = ezdxf.new(DXFVERSION, units=units.M) ``` -------------------------------- ### MLeader Block Content Example Source: https://ezdxf.readthedocs.io/en/stable/dxfinternals/entities/mleader.html Example of the CONTEXT_DATA structure for an MLeader entity containing Block content. ```text 300 CONTEXT_DATA{ 40 1.0 10 (x, y, z) 41 4.0 140 4.0 145 2.0 174 1 175 1 176 0 177 0 290 0 <<< has_mtext_content 296 1 <<< has_block_content <<< START Block content tags 341 #94 <<< dxf.block_record_handle 14 (0.0, 0.0, 1.0) <<< Block extrusion vector 15 (x, y, z) <<< Block location 16 (1.0, 1.0, 1.0) <<< Block scale vector, the x-, y- and z-axis scaling factors 46 0.0 <<< Block rotation in radians! 93 -1056964608 <<< Block color (raw value) 47 1.0 <<< start of transformation matrix (16x47) 47 0.0 47 0.0 47 18.427396871473 47 0.0 47 1.0 47 0.0 47 0.702618780008 47 0.0 47 0.0 47 1.0 47 0.0 47 0.0 47 0.0 47 0.0 47 1.0 <<< end of transformation matrix <<< END Block content tags 110 (0.0, 0.0, 0.0) <<< MLEADER plane origin point 111 (1.0, 0.0, 0.0) <<< MLEADER plane x-axis direction 112 (0.0, 1.0, 0.0) <<< MLEADER plane y-axis direction 297 0 <<< MLEADER normal reversed 302 LEADER{ ... 303 } 272 9 273 9 301 } ``` -------------------------------- ### Initialize DXF document with standard linetypes Source: https://ezdxf.readthedocs.io/en/stable/concepts/linetypes.html Create a new DXF document with standard linetypes enabled using the setup argument. ```python doc = ezdxf.new('R2007', setup=True) ``` -------------------------------- ### Install Python Build Requirements Source: https://ezdxf.readthedocs.io/en/stable/setup.html Install necessary system packages for compiling Python from source on Debian-based systems. ```bash sudo apt-get update sudo apt-get upgrade sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \ libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \ libncurses5-dev libncursesw5-dev xz-utils tk-dev ``` -------------------------------- ### Exporting to DXF using DXFBackend Source: https://ezdxf.readthedocs.io/en/stable/tutorials/image_export.html Demonstrates the process of creating a render context, initializing the DXF backend, and drawing the modelspace to a new DXF document. ```python from ezdxf.addons.drawing import Frontend, RenderContext, dxf def export(doc): export_doc = ezdxf.new() msp = doc.modelspace() # 1. create the render context context = RenderContext(doc) # 2. create the backend backend = dxf.DXFBackend(export_doc.modelspace()) # 3. create the frontend frontend = Frontend(context, backend) # 4. draw the modelspace frontend.draw_layout(msp) # 5. save or return DXF document export_doc.saveas("output_01.dxf") ``` -------------------------------- ### Install Matplotlib for Font Support Source: https://ezdxf.readthedocs.io/en/stable/disassemble.html Command to install the optional Matplotlib package for improved text boundary calculations. ```bash C:\> pip3 install matplotlib ``` -------------------------------- ### Render DXF to PDF using PyMuPdfBackend Source: https://ezdxf.readthedocs.io/en/stable/addons/drawing.html Initializes a frontend and renders the modelspace to a PDF file using the PyMuPdf backend. ```python import ezdxf from ezdxf.addons.drawing import Frontend, RenderContext from ezdxf.addons.drawing import layout, pymupdf doc = ezdxf.readfile("your.dxf") msp = doc.modelspace() backend = pymupdf.PyMuPdfBackend() Frontend(RenderContext(doc), backend).draw_layout(msp) with open("your.pdf", "wb") as fp: fp.write(backend.get_pdf_bytes(layout.Page(0, 0)) ``` -------------------------------- ### Get attribute with default value Source: https://ezdxf.readthedocs.io/en/stable/tasks/get_dxf_attributes.html Use the get method to retrieve an attribute value, providing a fallback if the attribute is missing. ```python e.dxf.get('color', 9) ``` -------------------------------- ### ezdxf.addons.openscad.is_installed Source: https://ezdxf.readthedocs.io/en/stable/addons/openscad.html Checks if OpenSCAD is installed on the system. ```APIDOC ## ezdxf.addons.openscad.is_installed() -> bool ### Description Returns True if OpenSCAD is detected on the system. It checks the configured path on Windows or the system command on Linux and macOS. ``` -------------------------------- ### page_setup(name='Layout1', fmt='ISO A3', landscape=True) Source: https://ezdxf.readthedocs.io/en/stable/drawing/drawing.html Creates or resets a paperspace layout with specific paper dimensions. ```APIDOC ## page_setup(name='Layout1', fmt='ISO A3', landscape=True) ### Description Creates a new paperspace layout if name does not exist or resets the existing layout. Requires DXF R2000 or newer. ### Parameters - **name** (str) - Optional - Paperspace layout name. - **fmt** (str) - Optional - Paper format. - **landscape** (bool) - Optional - True for landscape orientation, False for portrait. ``` -------------------------------- ### GeoJSON Output Format Source: https://ezdxf.readthedocs.io/en/stable/tutorials/geo.html Example structure of the resulting GeoJSON file. ```json { "type": "LineString", "coordinates": [ [ 15.430999, 47.06503 ], [ 15.431039, 47.064797 ], [ 15.431206, 47.064582 ], [ 15.431283, 47.064342 ], ... } ``` -------------------------------- ### Create and Duplicate MLeaderStyle Source: https://ezdxf.readthedocs.io/en/stable/dxfobjects/mleaderstyle.html Demonstrates how to initialize a new MLeaderStyle and how to duplicate an existing one. ```python import ezdxf doc = ezdxf.new() new_style = doc.mleader_styles.new("NewStyle") ``` ```python duplicated_style = doc.mleader_styles.duplicate_entry("Standard", "DuplicatedStyle") ``` -------------------------------- ### View DXF File via CLI Source: https://ezdxf.readthedocs.io/en/stable/launcher.html Commands to launch the DXF viewer and display help information. ```bash C:\> ezdxf view gear.dxf ``` ```bash C:\> ezdxf view -h usage: ezdxf view [-h] [-l LAYOUT] [--lwscale LWSCALE] [FILE] positional arguments: FILE DXF file to view optional arguments: -h, --help show this help message and exit -l LAYOUT, --layout LAYOUT select the layout to draw, default is "Model" --lwscale LWSCALE set custom line weight scaling, default is 0 to disable line weights at all ``` -------------------------------- ### ezdxf.math.EulerSpiral Source: https://ezdxf.readthedocs.io/en/stable/math/core.html Represents an Euler spiral (clothoid) starting at (0, 0). ```APIDOC ## class ezdxf.math.EulerSpiral(curvature: float = 1.0) ### Description Represents an euler spiral (clothoid) for curvature. This is a parametric curve starting at (0, 0). ### Methods - **radius(t: float) -> float**: Get radius of circle at distance t. - **tangent(t: float) -> Vec3**: Get tangent at distance t as Vec3 object. - **distance(radius: float) -> float**: Get distance L from origin for radius. - **point(t: float) -> Vec3**: Get point at distance t as Vec3. - **circle_center(t: float) -> Vec3**: Get circle center at distance t. - **approximate(length: float, segments: int) -> Iterable[Vec3]**: Approximate curve of length with line segments. - **bspline(length: float, segments: int = 10, degree: int = 3, method: str = 'uniform') -> BSpline**: Approximate euler spiral as B-spline. ``` -------------------------------- ### setup_local_grid Source: https://ezdxf.readthedocs.io/en/stable/dxfobjects/geodata.html Sets up a local grid coordinate system based on a design point and a reference point. ```APIDOC ## setup_local_grid(design_point, reference_point, north_direction=(0, 1), crs='EPSG:3395') ### Description Setup local grid coordinate system. This method is designed to setup CRS similar to EPSG:3395 World Mercator. ### Parameters - **design_point** (UVec) - Required - WCS coordinates of the CRS reference point - **reference_point** (UVec) - Required - CRS reference point in 2D cartesian coordinates - **north_direction** (UVec) - Optional - North direction a 2D vertex, default is (0, 1) - **crs** (str) - Optional - Coordinate Reference System definition XML string, default is the definition string for EPSG:3395 World Mercator ``` -------------------------------- ### DXF Tag Format Example Source: https://ezdxf.readthedocs.io/en/stable/drawing/management.html Standard DXF tag format representation. ```text 0 SECTION 2 HEADER 9 $ACADVER 1 AC1027 ... 9 $LIMMIN 10 0.0 20 0.0 9 $LIMMAX 10 420.0 20 297.0 9 $ORTHOMODE 70 0 9 $REGENMODE 70 1 ... 0 EOF ``` -------------------------------- ### Browse DXF Internal Structure Source: https://ezdxf.readthedocs.io/en/stable/launcher.html Commands to launch the DXF browser and display help information. ```bash C:\> ezdxf browse gear.dxf ``` ```bash C:\> ezdxf browse -h usage: ezdxf browse [-h] [-l LINE] [-g HANDLE] [FILE] positional arguments: FILE DXF file to browse optional arguments: -h, --help show this help message and exit -l LINE, --line LINE go to line number -g HANDLE, --handle HANDLE go to entity by HANDLE, HANDLE has to be a hex value without any prefix like 'fefe' ``` -------------------------------- ### Display ezdxf Version and Configuration Source: https://ezdxf.readthedocs.io/en/stable/launcher.html Use this command to verify the installed version, Python environment, C-extension status, and current configuration settings. ```bash C:\> ezdxf -Vv ezdxf v0.16.5b0 @ d:\source\ezdxf.git\src\ezdxf Python version: 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] using C-extensions: yes using Matplotlib: yes Configuration: [core] default_dimension_text_style = OpenSansCondensed-Light test_files = D:\Source\dxftest font_cache_directory = load_proxy_graphics = true store_proxy_graphics = true log_unprocessed_tags = false filter_invalid_xdata_group_codes = true write_fixed_meta_data_for_testing = false disable_c_ext = false [browse-command] text_editor = "C:\Program Files\Notepad++\notepad++.exe" "{filename}" -n{num} Environment Variables: EZDXF_DISABLE_C_EXT= EZDXF_TEST_FILES=D:\Source\dxftest EZDXF_CONFIG_FILE= Existing Configuration Files: C:\Users\manfred\.config\ezdxf\ezdxf.ini ``` -------------------------------- ### Get Block Entities Source: https://ezdxf.readthedocs.io/en/stable/tasks/get_entity_content.html Retrieves virtual DXF entities from an INSERT entity. ```python for insert in msp.query("INSERT"): for entity in insert.virtual_entities(): print(str(entity)) ``` -------------------------------- ### ezdxf.render.Bezier.start Source: https://ezdxf.readthedocs.io/en/stable/render/curves.html Sets the starting point and the initial tangent vector for the bezier curve. ```APIDOC ## start(point, tangent) ### Description Set start point and start tangent for the Bezier curve. ### Parameters - **point** (UVec) - Required - Start point - **tangent** (UVec) - Required - Start tangent as vector ``` -------------------------------- ### ezdxf.edgeminer.find_loop_by_edge Source: https://ezdxf.readthedocs.io/en/stable/edgeminer.html Returns the first loop found including the specified start edge. ```APIDOC ## ezdxf.edgeminer.find_loop_by_edge(deposit, start, clockwise=True) ### Description Returns the first loop found including the given start edge. Returns an empty sequence if no loop was found. ### Parameters - **deposit** (Deposit) - Required - Edge deposit - **start** (Edge) - Required - Starting edge - **clockwise** (bool) - Optional - Search orientation ``` -------------------------------- ### Create a new DXF document Source: https://ezdxf.readthedocs.io/en/stable/usage_for_beginners.html Initializes a new DXF document. Supports specifying a version or enabling default resource setup. ```python doc = ezdxf.new() ``` ```python doc = ezdxf.new("R12") ``` ```python doc = ezdxf.new(setup=True) ``` -------------------------------- ### Create DXF with Predefined Resources Source: https://ezdxf.readthedocs.io/en/stable/tutorials/simple_drawings.html Initializes a document with standard resources enabled and applies a dashed linetype to a line entity. ```python import ezdxf doc = ezdxf.new("R2010", setup=True) msp = doc.modelspace() msp.add_line((0, 0), (10, 0), dxfattribs={"linetype": "DASHED"}) ``` -------------------------------- ### ezdxf.tools.guid Source: https://ezdxf.readthedocs.io/en/stable/low_level_tools/functions.html Generates a unique ID string matching the AutoCAD GUID pattern. ```APIDOC ## ezdxf.tools.guid() -> str ### Description Returns a general unique ID based on uuid.uuid4(), formatted as {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}. ``` -------------------------------- ### Initialize DXF Document for TablePainter Source: https://ezdxf.readthedocs.io/en/stable/addons/tablepainter.html Sets up a new DXF document with required header settings and text styles for table rendering. ```python import ezdxf from ezdxf.enums import MTextEntityAlignment from ezdxf.addons import TablePainter doc = ezdxf.new("R2000") # required for lineweight support doc.header["$LWDISPLAY"] = 1 # show lineweights doc.styles.add("HEAD", font="OpenSans-ExtraBold.ttf") doc.styles.add("CELL", font="OpenSans-Regular.ttf") ``` -------------------------------- ### Get application-defined data Source: https://ezdxf.readthedocs.io/en/stable/appdata.html Check for the existence of application data and retrieve the associated tags. ```python if entity.has_app_data("YOURAPPID"): tags = entity.get_app_data("YOURAPPID") # tags content is [DXFTag(1, 'DataString')] ``` -------------------------------- ### ezdxf.edgeminer.find_all_simple_chains Source: https://ezdxf.readthedocs.io/en/stable/edgeminer.html Returns all simple chains from a deposit, where chains start and end at a leaf or junction. ```APIDOC ## ezdxf.edgeminer.find_all_simple_chains(deposit) ### Description Returns all simple chains from deposit. Each chain starts and ends at a leaf (degree of 1) or a junction (degree greater than 2). ### Parameters - **deposit** (Deposit) - Required - Edge deposit ``` -------------------------------- ### ezdxf.edgeminer.find_simple_chain Source: https://ezdxf.readthedocs.io/en/stable/edgeminer.html Returns a simple chain containing the start edge, ending at a leaf or junction. ```APIDOC ## ezdxf.edgeminer.find_simple_chain(deposit, start) ### Description Returns a simple chain containing start edge. A simple chain starts and ends at a leaf or a junction. ### Parameters - **deposit** (Deposit) - Required - Edge deposit - **start** (Edge) - Required - Starting edge ``` -------------------------------- ### execute(xref_prefix: str = '') Source: https://ezdxf.readthedocs.io/en/stable/xref.html Execute all loading commands. ```APIDOC ### execute(xref_prefix: str = '') Execute all loading commands. The xref_prefix string is used as XREF name when the conflict policy `ConflictPolicy.XREF_PREFIX` is applied. ``` -------------------------------- ### Example result dictionary for layer grouping Source: https://ezdxf.readthedocs.io/en/stable/tasks/groupby.html The output structure when grouping entities by the 'layer' attribute. ```json { '0': [ ... list of entities ], 'ExampleLayer1': [ ... ], 'ExampleLayer2': [ ... ], ... } ``` -------------------------------- ### Create a Radius Dimension Source: https://ezdxf.readthedocs.io/en/stable/tutorials/radius_dimension.html Demonstrates initializing a DXF document, adding a circle, and creating a radius dimension entity with a specific angle and style. ```python import ezdxf # DXF R2010 drawing, official DXF version name: 'AC1024', # setup=True setups the default dimension styles doc = ezdxf.new("R2010", setup=True) msp = doc.modelspace() # add new dimension entities to the modelspace msp.add_circle((0, 0), radius=3) # add a CIRCLE entity, not required # add default radius dimension, measurement text is located outside dim = msp.add_radius_dim( center=(0, 0), radius=3, angle=45, dimstyle="EZ_RADIUS" ) # necessary second step, to create the BLOCK entity with the dimension geometry. dim.render() doc.saveas("radius_dimension.dxf") ``` -------------------------------- ### Define Axis-Ordering in XML Source: https://ezdxf.readthedocs.io/en/stable/dxfobjects/geodata.html Example of the XML structure defining axis-ordering and direction for the coordinate system. ```xml 1 Easting E east 2 Northing N north ``` -------------------------------- ### Importing ezdxf Source: https://ezdxf.readthedocs.io/en/stable/usage_for_beginners.html The initial step required to use the ezdxf package. ```python import ezdxf ``` -------------------------------- ### Set and Get Linetype Scale Source: https://ezdxf.readthedocs.io/en/stable/tutorials/common_graphical_attributes.html The ltscale attribute scales linetype patterns. It defaults to 1.0. ```python entity.dxf.ltscale = 2.0 ``` ```python scale = entity.dxf.ltscale ``` -------------------------------- ### Access DXF header variables Source: https://ezdxf.readthedocs.io/en/stable/howto/document.html Interface for getting and setting values in the document header section. ```python doc.header["VarName"] = value value = doc.header["VarName"] ``` -------------------------------- ### openscad.is_installed() Source: https://ezdxf.readthedocs.io/en/stable/addons/openscad.html Checks if the OpenSCAD application is available on the system. ```APIDOC ## openscad.is_installed() ### Description Returns a boolean indicating whether the OpenSCAD application is correctly configured and accessible by the add-on. ```