本文整理匯總了Python中ezdxf.new方法的典型用法代碼示例。如果您正苦於以下問題:Python ezdxf.new方法的具體用法?Python ezdxf.new怎麽用?Python ezdxf.new使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ezdxf
的用法示例。
在下文中一共展示了ezdxf.new方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: dxf_frame
# 需要導入模塊: import ezdxf [as 別名]
# 或者: from ezdxf import new [as 別名]
def dxf_frame(
vpoints: Sequence[VPoint],
v_to_slvs: Callable[[], Iterable[Tuple[int, int]]],
version: str,
file_name: str
):
"""Create frame sketch only."""
dwg = ezdxf.new(version)
msp = dwg.modelspace()
for p1, p2 in v_to_slvs():
vp1 = vpoints[p1]
vp2 = vpoints[p2]
msp.add_line((vp1.cx, vp1.cy), (vp2.cx, vp2.cy))
dwg.saveas(file_name)
示例2: main
# 需要導入模塊: import ezdxf [as 別名]
# 或者: from ezdxf import new [as 別名]
def main():
def make(dxfversion, filename):
doc = ezdxf.new(dxfversion)
if 'VIEWPORTS' not in doc.layers:
vp_layer = doc.layers.new('VIEWPORTS')
else:
vp_layer = doc.layers.get('VIEWPORTS')
# switch viewport layer off to hide the viewport border lines
vp_layer.off()
create_2d_modelspace_content(doc.modelspace())
create_3d_modelspace_content(doc.modelspace())
# IMPORTANT: DXF R12 supports only one paper space aka layout, every layout name returns the same layout
layout = doc.layout('Layout1') # default layout
layout.page_setup(size=(22, 17), margins=(1, 1, 1, 1), units='inch')
create_viewports(layout, dxfversion)
try:
doc.saveas(filename)
except IOError:
print("Can't write: '%s'" % filename)
make('AC1009', 'viewports_in_paperspace_R12.dxf')
make('AC1015', 'viewports_in_paperspace_R2000.dxf')
make('AC1021', 'viewports_in_paperspace_R2007.dxf')
示例3: run
# 需要導入模塊: import ezdxf [as 別名]
# 或者: from ezdxf import new [as 別名]
def run():
doc = ezdxf.new('R2004') # does not work with AC1015/R2000, but it should
doc.header['$SORTENTS'] = SortEntities.REGEN
msp = doc.modelspace()
add_solids(msp, count=1000, min_size=3, max_size=7)
doc.saveas('sort_solids_unordered.dxf')
order_solids_by_color(msp) # 1 -> 7
doc.saveas('sort_solids_ordered.dxf')
reverse_order_solids_by_color(msp) # 7 -> 1
doc.saveas('sort_solids_reversed_ordered.dxf')
move_solids_on_top(msp, 6) # 7, 5, 4, 3, 2, 1, 6
doc.saveas('sort_solids_6_on_top.dxf') # 6 is magenta
# AutoCAD has no problem with removed entities in the redraw order table (SORTENTSTABLE)
remove_solids(msp, 6)
doc.saveas('sort_solids_removed_color_6.dxf')
示例4: main_ellipse
# 需要導入模塊: import ezdxf [as 別名]
# 或者: from ezdxf import new [as 別名]
def main_ellipse(layout):
entity, vertices, axis_vertices = ellipse(start=math.pi / 2, end=-math.pi / 2)
axis = Vector.random()
angle = random_angle()
entity, vertices, axis_vertices = synced_rotation(entity, vertices, axis_vertices, axis=axis, angle=angle)
entity, vertices, axis_vertices = synced_translation(
entity, vertices, axis_vertices,
dx=random.uniform(-2, 2),
dy=random.uniform(-2, 2),
dz=random.uniform(-2, 2)
)
for sx, sy, sz in UNIFORM_SCALING + NON_UNIFORM_SCALING:
entity0, vertices0, axis0 = synced_scaling(entity, vertices, axis_vertices, sx, sy, sz)
add(layout, entity0, vertices0, layer=f'new ellipse')
layout.add_line(axis0[0], axis0[2], dxfattribs={'color': 6, 'linetype': 'DASHED', 'layer': 'old axis'})
layout.add_line(axis0[1], axis0[3], dxfattribs={'color': 6, 'linetype': 'DASHED', 'layer': 'old axis'})
p = list(entity0.vertices([0, math.pi / 2, math.pi, math.pi * 1.5]))
layout.add_line(p[0], p[2], dxfattribs={'color': 1, 'layer': 'new axis'})
layout.add_line(p[1], p[3], dxfattribs={'color': 3, 'layer': 'new axis'})
示例5: main_insert2
# 需要導入模塊: import ezdxf [as 別名]
# 或者: from ezdxf import new [as 別名]
def main_insert2(layout):
entity, vertices = insert()
m = Matrix44.chain(
Matrix44.scale(-1.1, 1.1, 1),
Matrix44.z_rotate(math.radians(10)),
Matrix44.translate(1, 1, 1),
)
doc.layers.new('exploded axis', dxfattribs={'color': -7})
for i in range(5):
entity, vertices = synced_transformation(entity, vertices, m)
layout.entitydb.add(entity)
layout.add_entity(entity)
origin, x, y, z = list(vertices)
layout.add_line(origin, x, dxfattribs={'color': 2, 'layer': 'new axis'})
layout.add_line(origin, y, dxfattribs={'color': 4, 'layer': 'new axis'})
layout.add_line(origin, z, dxfattribs={'color': 6, 'layer': 'new axis'})
for line in entity.virtual_entities():
line.dxf.layer = 'exploded axis'
line.dxf.color = 7
layout.entitydb.add(line)
layout.add_entity(line)
示例6: radius_default_inside_horizontal
# 需要導入模塊: import ezdxf [as 別名]
# 或者: from ezdxf import new [as 別名]
def radius_default_inside_horizontal(dxfversion='R2000', delta=10, dimtmove=0):
doc = ezdxf.new(dxfversion, setup=True)
style = doc.dimstyles.get('EZ_RADIUS_INSIDE')
style.dxf.dimtmove = dimtmove
msp = doc.modelspace()
for x, y in multiple_locations(delta=delta):
angle = Vector(x, y).angle_deg
msp.add_circle((x, y), radius=3)
dim = msp.add_radius_dim(center=(x, y), radius=3, angle=angle, dimstyle='EZ_RADIUS_INSIDE',
override={
'dimtih': 1, # force text inside horizontal
})
dim.render(discard=BRICSCAD)
doc.set_modelspace_vport(height=3 * delta)
doc.saveas(OUTDIR / f'dim_radius_{dxfversion}_default_inside_horizontal_dimtmove_{dimtmove}.dxf')
示例7: radius_user_defined_outside
# 需要導入模塊: import ezdxf [as 別名]
# 或者: from ezdxf import new [as 別名]
def radius_user_defined_outside(dxfversion='R2000', delta=15):
def add_dim(x, y, radius, dimtad):
center = Vector(x, y)
msp.add_circle((x, y), radius=3)
dim_location = center + Vector.from_deg_angle(angle, radius)
dim = msp.add_radius_dim(center=(x, y), radius=3, location=dim_location, dimstyle='EZ_RADIUS',
override={
'dimtad': dimtad,
})
dim.render(discard=BRICSCAD)
doc = ezdxf.new(dxfversion, setup=True)
msp = doc.modelspace()
for x, y in multiple_locations(delta=delta):
angle = Vector(x, y).angle_deg
add_dim(x, y, 5, dimtad=1) # above
add_dim(x + 3 * delta, y, 5, dimtad=0) # center
add_dim(x + 6 * delta, y, 5, dimtad=4) # below
doc.set_modelspace_vport(height=3 * delta, center=(4.5 * delta, 0))
doc.saveas(OUTDIR / f'dim_radius_{dxfversion}_user_defined_outside.dxf')
示例8: radius_user_defined_outside_horizontal
# 需要導入模塊: import ezdxf [as 別名]
# 或者: from ezdxf import new [as 別名]
def radius_user_defined_outside_horizontal(dxfversion='R2000', delta=15):
def add_dim(x, y, radius, dimtad):
center = Vector(x, y)
msp.add_circle((x, y), radius=3)
dim_location = center + Vector.from_deg_angle(angle, radius)
dim = msp.add_radius_dim(center=(x, y), radius=3, location=dim_location, dimstyle='EZ_RADIUS',
override={
'dimtad': dimtad,
'dimtoh': 1, # force text outside horizontal
})
dim.render(discard=BRICSCAD)
doc = ezdxf.new(dxfversion, setup=True)
msp = doc.modelspace()
for x, y in multiple_locations(delta=delta):
angle = Vector(x, y).angle_deg
add_dim(x, y, 5, dimtad=1) # above
add_dim(x + 3 * delta, y, 5, dimtad=0) # center
add_dim(x + 6 * delta, y, 5, dimtad=4) # below
doc.set_modelspace_vport(height=3 * delta, center=(4.5 * delta, 0))
doc.saveas(OUTDIR / f'dim_radius_{dxfversion}_user_defined_outside_horizontal.dxf')
示例9: radius_user_defined_inside
# 需要導入模塊: import ezdxf [as 別名]
# 或者: from ezdxf import new [as 別名]
def radius_user_defined_inside(dxfversion='R2000', delta=10, dimtmove=0):
def add_dim(x, y, radius, dimtad):
center = Vector(x, y)
msp.add_circle((x, y), radius=3)
dim_location = center + Vector.from_deg_angle(angle, radius)
dim = msp.add_radius_dim(center=(x, y), radius=3, location=dim_location, dimstyle='EZ_RADIUS',
override={
'dimtad': dimtad,
})
dim.render(discard=BRICSCAD)
doc = ezdxf.new(dxfversion, setup=True)
style = doc.dimstyles.get('EZ_RADIUS')
style.dxf.dimtmove = dimtmove
msp = doc.modelspace()
for x, y in multiple_locations(delta=delta):
angle = Vector(x, y).angle_deg
add_dim(x, y, 1, dimtad=1) # above
add_dim(x + 3 * delta, y, 1, dimtad=0) # center
add_dim(x + 6 * delta, y, 1, dimtad=4) # below
doc.set_modelspace_vport(height=3 * delta, center=(4.5 * delta, 0))
doc.saveas(OUTDIR / f'dim_radius_{dxfversion}_user_defined_inside_dimtmove_{dimtmove}.dxf')
示例10: radius_user_defined_inside_horizontal
# 需要導入模塊: import ezdxf [as 別名]
# 或者: from ezdxf import new [as 別名]
def radius_user_defined_inside_horizontal(dxfversion='R2000', delta=10):
def add_dim(x, y, radius, dimtad):
center = Vector(x, y)
msp.add_circle((x, y), radius=3)
dim_location = center + Vector.from_deg_angle(angle, radius)
dim = msp.add_radius_dim(center=(x, y), radius=3, location=dim_location, dimstyle='EZ_RADIUS',
override={
'dimtad': dimtad,
'dimtih': 1, # force text inside horizontal
})
dim.render(discard=BRICSCAD)
doc = ezdxf.new(dxfversion, setup=True)
msp = doc.modelspace()
for x, y in multiple_locations(delta=delta):
angle = Vector(x, y).angle_deg
add_dim(x, y, 1, dimtad=1) # above
add_dim(x + 3 * delta, y, 1, dimtad=0) # center
add_dim(x + 6 * delta, y, 1, dimtad=4) # below
doc.set_modelspace_vport(height=3 * delta, center=(4.5 * delta, 0))
doc.saveas(OUTDIR / f'dim_radius_{dxfversion}_user_defined_inside_horizontal.dxf')
示例11: create_gear
# 需要導入模塊: import ezdxf [as 別名]
# 或者: from ezdxf import new [as 別名]
def create_gear(filename, teeth=20, outside_radius=10, top_width=2, bottom_width=3, height=2):
doc = ezdxf.new('R2000')
msp = doc.modelspace()
vertices = zip(
forms.gear(
count=teeth,
top_width=top_width,
bottom_width=bottom_width,
height=height,
outside_radius=outside_radius,
),
cycle([0, .1, 0, .1]) # bulge values: top, down flank, bottom, up flank
)
msp.add_lwpolyline(
vertices,
format='vb',
dxfattribs={'closed': True}
)
doc.saveas(filename)
示例12: diameter_default_inside_horizontal
# 需要導入模塊: import ezdxf [as 別名]
# 或者: from ezdxf import new [as 別名]
def diameter_default_inside_horizontal(dxfversion='R2000', delta=10, dimtmove=0):
doc = ezdxf.new(dxfversion, setup=True)
style = doc.dimstyles.get('EZ_RADIUS_INSIDE')
style.dxf.dimtmove = dimtmove
msp = doc.modelspace()
for x, y in multiple_locations(delta=delta):
angle = Vector(x, y).angle_deg
msp.add_circle((x, y), radius=3)
dim = msp.add_diameter_dim(center=(x, y), radius=3, angle=angle, dimstyle='EZ_RADIUS_INSIDE',
override={
'dimtih': 1, # force text inside horizontal
})
dim.render(discard=BRICSCAD)
doc.set_modelspace_vport(height=3 * delta)
doc.saveas(OUTDIR / f'dim_diameter_{dxfversion}_default_inside_horizontal_dimtmove_{dimtmove}.dxf')
示例13: diameter_user_defined_outside
# 需要導入模塊: import ezdxf [as 別名]
# 或者: from ezdxf import new [as 別名]
def diameter_user_defined_outside(dxfversion='R2000', delta=15):
def add_dim(x, y, radius, dimtad):
center = Vector(x, y)
msp.add_circle((x, y), radius=3)
dim_location = center + Vector.from_deg_angle(angle, radius)
dim = msp.add_diameter_dim(center=(x, y), radius=3, location=dim_location, dimstyle='EZ_RADIUS',
override={
'dimtad': dimtad,
})
dim.render(discard=BRICSCAD)
doc = ezdxf.new(dxfversion, setup=True)
msp = doc.modelspace()
for x, y in multiple_locations(delta=delta):
angle = Vector(x, y).angle_deg
add_dim(x, y, 5, dimtad=1) # above
add_dim(x + 3 * delta, y, 5, dimtad=0) # center
add_dim(x + 6 * delta, y, 5, dimtad=4) # below
doc.set_modelspace_vport(height=3 * delta, center=(4.5 * delta, 0))
doc.saveas(OUTDIR / f'dim_diameter_{dxfversion}_user_defined_outside.dxf')
示例14: diameter_user_defined_outside_horizontal
# 需要導入模塊: import ezdxf [as 別名]
# 或者: from ezdxf import new [as 別名]
def diameter_user_defined_outside_horizontal(dxfversion='R2000', delta=15):
def add_dim(x, y, radius, dimtad):
center = Vector(x, y)
msp.add_circle((x, y), radius=3)
dim_location = center + Vector.from_deg_angle(angle, radius)
dim = msp.add_diameter_dim(center=(x, y), radius=3, location=dim_location, dimstyle='EZ_RADIUS',
override={
'dimtad': dimtad,
'dimtoh': 1, # force text outside horizontal
})
dim.render(discard=BRICSCAD)
doc = ezdxf.new(dxfversion, setup=True)
msp = doc.modelspace()
for x, y in multiple_locations(delta=delta):
angle = Vector(x, y).angle_deg
add_dim(x, y, 5, dimtad=1) # above
add_dim(x + 3 * delta, y, 5, dimtad=0) # center
add_dim(x + 6 * delta, y, 5, dimtad=4) # below
doc.set_modelspace_vport(height=3 * delta, center=(4.5 * delta, 0))
doc.saveas(OUTDIR / f'dim_diameter_{dxfversion}_user_defined_outside_horizontal.dxf')
示例15: diameter_user_defined_inside
# 需要導入模塊: import ezdxf [as 別名]
# 或者: from ezdxf import new [as 別名]
def diameter_user_defined_inside(dxfversion='R2000', delta=10, dimtmove=0):
def add_dim(x, y, radius, dimtad):
center = Vector(x, y)
msp.add_circle((x, y), radius=3)
dim_location = center + Vector.from_deg_angle(angle, radius)
dim = msp.add_diameter_dim(center=(x, y), radius=3, location=dim_location, dimstyle='EZ_RADIUS',
override={
'dimtad': dimtad,
})
dim.render(discard=BRICSCAD)
doc = ezdxf.new(dxfversion, setup=True)
style = doc.dimstyles.get('EZ_RADIUS')
style.dxf.dimtmove = dimtmove
msp = doc.modelspace()
for x, y in multiple_locations(delta=delta):
angle = Vector(x, y).angle_deg
add_dim(x, y, 1, dimtad=1) # above
add_dim(x + 3 * delta, y, 1, dimtad=0) # center
add_dim(x + 6 * delta, y, 1, dimtad=4) # below
doc.set_modelspace_vport(height=3 * delta, center=(4.5 * delta, 0))
doc.saveas(OUTDIR / f'dim_diameter_{dxfversion}_user_defined_inside_dimtmove_{dimtmove}.dxf')