Create a copy of an entity by entity.copy()
, the new entity has a new handle but no owner
(correct owner handle = '0') everything else is identical to the source entity.
Without adding the new entity to a layout by layout.add_entity()
, the new entity will not show up in
the saved DXF file. You can add the new entity to any layout type: model space, paper space layout or block layout
Copy entity to another layout by simplified method call entity.copy_to_layout()
:
# create a duplicate
new_entity = entity.copy()
# add duplicate to another layout
another_layout.add_entity(new_entity)
# simplified method call
entity.copy_to_layout(another_layout)
Move entity to another layout by entity.move_to_layout()
:
# move entity from old_layout to new_layout
old_layout.move_to_layout(entity, new_layout)
# simplified method call, but works only for entities in model space or
# paper space layouts
entity.move_to_layout(new_layout)
# for DXF R12 and entity resides in a block layout, it is faster to provide the source layout
# because ezdxf has to search all block layouts
entity.move_to_layout(new_layout, source=old_block_layout)
Splines defined by control points do not go through control points as splines defined by fit points.
The layout.add_spline()
just created splines with fit points automatically, if you wanted splines with control
points the setup had to be done by yourself.
spline = layout.add_spline()
spline.set_control_points(control_points)
# set correct knot vector, if you know how to construct a valid knot array
spline.set_knot_values(knot_values)
# and set flags
spline.dxf.flags = spline.PERIODIC | spline.RATIONAL
This procedure is now simplified by 4 new factory functions.
Layout.add_open_spline(control_points, degree=3, knots=None, dxfattribs=None)
Add an open uniform B-spline, control_points is a list of (x, y, z) tuples, degree specifies degree of spline, knots values by default not necessary. (requires DXF version R2000+)
Open uniform B-splines start and end at your first and last control points.
Layout.add_closed_spline(control_points, degree=3, knots=None, dxfattribs=None)
Add a closed uniform B-spline, control_points is a list of (x, y, z) tuples, degree specifies degree of spline, knots values by default not necessary. (requires DXF version R2000+)
Closed uniform B-splines is a closed curve start and end at the first control points.
Layout.add_rational_spline(control_points, weights, degree=3, knots=None, dxfattribs=None)
Add an open rational uniform B-spline, control_points is a list of (x, y, z) tuples, weights is a list of values, which defines the influence of the associated control point, therefor count of control points has to be equal to the count of weights, degree specifies degree of spline, knots values by default not necessary. (requires DXF version R2000+)
Open rational uniform B-splines start and end at your first and last control points, and have additional control possibilities by weighting each control point.
Layout.add_closed_rational_spline(control_points, weights, degree=3, knots=None, dxfattribs=None)
Add a closed rational uniform B-spline, control_points is a list of (x, y, z) tuples, weights is a list of values, which defines the influence of the associated control point, therefor count of control points has to be equal to the count of weights, degree specifies degree of spline, knots values by default not necessary. (requires DXF version R2000+)
Closed rational uniform B-splines start and end at the first control point, and have additional control possibilities by weighting each control point.
Examples:
Added a more convenient method to get/set binary coded flags.