How to use the ezdxf.new function in ezdxf

To help you get started, we’ve selected a few ezdxf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozman / ezdxf / tests / test_04_dxf_high_level_structs / test_newdrawings.py View on Github external
def test_new_AC1021():
    dwg = ezdxf.new('AC1021')
    assert 'AC1021' == dwg.dxfversion
github mozman / ezdxf / tests / test_dxf_structures / test_sections.py View on Github external
def sections():
    dwg = ezdxf.new('R12')
    return Sections(load_dxf_structure(internal_tag_compiler(TEST_HEADER)), dwg)
github mozman / ezdxf / tests / test_tools.py View on Github external
def test_drawing():
    dwg = ezdxf.new('AC1024')
    for attr in getattributes(DrawingProxy('AC1024')):
        if not hasattr(dwg, attr):
            raise Exception("attribute '%s' of DrawingProxy() does not exist in Drawing() class" % attr)
github mozman / ezdxf / tests / test_08_addons / test_804_importer.py View on Github external
def create_source_drawing(version):
    dwg = ezdxf.new(version)
    dwg.layers.new('Test', dxfattribs={'color': 17})
    dwg.layers.new('TestConflict', dxfattribs={'color': 18})
    msp = dwg.modelspace()
    msp.add_line((0, 0), (10, 0))
    msp.add_circle((0, 0), radius=5)
    msp.add_blockref("TestBlock", insert=(0, 0))
    msp.add_blockref("ConflictBlock", insert=(0, 0))
    build_block(dwg, "TestBlock")
    build_block(dwg, "ConflictBlock")
    block = build_block(dwg, "RefToConflictBlock")
    block.add_blockref('ConflictBlock', insert=(0, 0))
    return dwg
github mozman / ezdxf / examples / addons / pycsg_sphere_vs_menger_sponge.py View on Github external
# Copyright (c) 2020, Manfred Moitzi
# License: MIT License
from pathlib import Path
from time import perf_counter
import ezdxf

from ezdxf.render.forms import sphere
from ezdxf.addons import MengerSponge
from ezdxf.addons.pycsg import CSG

DIR = Path('~/Desktop/Outbox').expanduser()

doc = ezdxf.new()
doc.layers.new('sponge', dxfattribs={'color': 5})
doc.layers.new('sphere', dxfattribs={'color': 6})

doc.set_modelspace_vport(6, center=(5, 0))
msp = doc.modelspace()

sponge1 = MengerSponge(level=3).mesh()
sphere1 = sphere(count=32, stacks=16, radius=.5, quads=True).translate(.25, .25, 1)

t0 = perf_counter()
subtract = (CSG(sponge1, meshid=1) - CSG(sphere1, meshid=2))
t1 = perf_counter()
# get mesh result by id
subtract.mesh(1).render(msp, dxfattribs={'layer': 'sponge'})
subtract.mesh(2).render(msp, dxfattribs={'layer': 'sphere'})
github mozman / ezdxf / examples / render / dimension_linear.py View on Github external
def linear_tutorial_ext_lines():
    doc = ezdxf.new('R12', setup=True)
    msp = doc.modelspace()

    msp.add_line((0, 0), (3, 0))

    attributes = {
        'dimexo': 0.5,
        'dimexe': 0.5,
        'dimdle': 0.5,
        'dimblk': ezdxf.ARROWS.none,
        'dimclrt': 3,
    }
    msp.add_linear_dim(base=(3, 2), p1=(0, 0), p2=(3, 0), dimstyle='EZDXF', override=attributes).render()

    attributes = {
        'dimtad': 4,
        'dimclrd': 2,
github mozman / ezdxf / examples / optimize_polyfaces.py View on Github external
filename = SRCDIR / name

    print(f'opening DXF file: {filename}')
    start_time = time.time()
    doc = ezdxf.readfile(filename)
    msp = doc.modelspace()
    end_time = time.time()
    print(f'time for reading: {end_time - start_time:.1f} seconds')
    print(f"DXF version: {doc.dxfversion}")
    print(f"Database contains {len(doc.entitydb)} entities.")
    polyfaces = (polyline for polyline in msp.query('POLYLINE') if polyline.is_poly_face_mesh)

    # create a new documents
    doc1 = ezdxf.new()
    msp1 = doc1.modelspace()
    doc2 = ezdxf.new()
    msp2 = doc2.modelspace()
    for polyface in polyfaces:
        b = MeshVertexMerger.from_polyface(polyface)
        b.render(msp1, dxfattribs={
            'layer': polyface.dxf.layer,
            'color': polyface.dxf.color,
        })
        b.render_polyface(msp2, dxfattribs={
            'layer': polyface.dxf.layer,
            'color': polyface.dxf.color,
        })

    new_filename = OUTDIR / ('mesh_' + name)
    print(f'saving as mesh DXF file: {new_filename}')
    start_time = time.time()
    doc1.saveas(new_filename)