def import_paperspace_layout(self, name: str) -> "Layout": """Import paperspace layout `name` into the target document. Recreates the source paperspace layout in the target document, renames the target paperspace if a paperspace with same `name` already exist and imports all entities from the source paperspace into the target paperspace. Args: name: source paper space name as string Returns: new created target paperspace :class:`Layout` Raises: KeyError: source paperspace does not exist DXFTypeError: invalid modelspace import """ if name.lower() == "model": raise const.DXFTypeError( "Can not import modelspace, use method import_modelspace().") source_layout = self.source.layouts.get(name) target_layout = self.recreate_source_layout(name) self.import_entities(source_layout, target_layout) return target_layout
def add_object(self, entity: "DXFObject") -> None: """Add `entity` to OBJECTS section. (internal API)""" if is_dxf_object(entity): self._entity_space.add(entity) else: raise const.DXFTypeError( f"invalid DXF type {entity.dxftype()} for OBJECTS section" )
def add_entry(self, entry: 'DXFEntity') -> None: """ Add a table `entry`, created by other object than this table. (internal API) """ if entry.dxftype() != self._head.dxf.name: raise const.DXFTypeError( f'Invalid table entry type {entry.dxftype()} ' f'for table {self.name}') name = entry.dxf.name if self.has_entry(name): raise const.DXFTableEntryError( f'{self._head.dxf.name} {name} already exists!') entry.doc = self.doc entry.owner = self._head.dxf.handle self._append(entry)
def add_entry(self, entry: T) -> None: """Add a table `entry`, created by other object than this table. (internal API) """ if entry.dxftype() != self.TABLE_TYPE: raise const.DXFTypeError( f"Invalid table entry type {entry.dxftype()} " f"for table {self.TABLE_TYPE}" ) name = entry.dxf.name if self.has_entry(name): raise const.DXFTableEntryError( f"{self._head.dxf.name} {name} already exists!" ) entry.doc = self.doc entry.dxf.owner = self._head.dxf.handle self._append(entry)
def copy(self): raise const.DXFTypeError("Copying of MLINESTYLE not supported.")
def copy(self) -> 'DXFEntity': raise const.DXFTypeError( f'Cloning of tag storage {self.dxftype()} not supported.')
def copy(self) -> "DXFGraphicProxy": raise const.DXFTypeError( f"Cloning of DXFGraphicProxy() not supported.")
def copy(self): raise const.DXFTypeError('Copying of GROUP not supported.')
def copy(self): raise const.DXFTypeError(f"Cloning of {self.dxftype()} not supported.")
def page_setup(self, size: Tuple[float, float] = (297, 210), margins: Tuple[float, float, float, float] = (10, 15, 10, 15), units: str = 'mm', offset: Tuple[float, float] = (0, 0), rotation: int = 0, scale: int = 16, name: str = 'ezdxf', device: str = 'DWG to PDF.pc3') -> None: """ Setup plot settings and paper size and reset viewports. All parameters in given `units` (mm or inch). Reset paper limits, extends and viewports. Args: size: paper size as (width, height) tuple margins: (top, right, bottom, left) hint: clockwise units: "mm" or "inch" offset: plot origin offset is 2D point rotation: see table Rotation scale: integer in range [0, 32] defines a standard scale type or as tuple(numerator, denominator) e.g. (1, 50) for scale 1:50 name: paper name prefix "{name}_({width}_x_{height}_{unit})" device: device .pc3 configuration file or system printer name === ============ int Rotation === ============ 0 no rotation 1 90 degrees counter-clockwise 2 upside-down 3 90 degrees clockwise === ============ """ if int(rotation) not in (0, 1, 2, 3): raise const.DXFValueError("valid rotation values: 0-3") if isinstance(scale, tuple): standard_scale = 16 elif isinstance(scale, int): standard_scale = scale scale = const.STD_SCALES.get(standard_scale, (1, 1)) else: raise const.DXFTypeError( "Scale has to be an int or a tuple(numerator, denominator)") if scale[0] == 0: raise const.DXFValueError("Scale numerator can't be 0.") if scale[1] == 0: raise const.DXFValueError("Scale denominator can't be 0.") self.use_standard_scale(False) # works best, don't know why paper_width, paper_height = size margin_top, margin_right, margin_bottom, margin_left = margins units = units.lower() if units.startswith('inch'): units = 'Inches' plot_paper_units = 0 unit_factor = 25.4 # inch to mm elif units == 'mm': units = 'MM' plot_paper_units = 1 unit_factor = 1.0 else: raise const.DXFValueError('Supported units: "mm" and "inch"') # Setup PLOTSETTINGS # all paper sizes in mm dxf = self.dxf_layout.dxf dxf.page_setup_name = '' dxf.plot_configuration_file = device dxf.paper_size = f'{name}_({paper_width:.2f}_x_{paper_height:.2f}_{units})' dxf.left_margin = margin_left * unit_factor dxf.bottom_margin = margin_bottom * unit_factor dxf.right_margin = margin_right * unit_factor dxf.top_margin = margin_top * unit_factor dxf.paper_width = paper_width * unit_factor dxf.paper_height = paper_height * unit_factor dxf.scale_numerator = scale[0] dxf.scale_denominator = scale[1] dxf.plot_paper_units = plot_paper_units dxf.plot_rotation = rotation x_offset, y_offset = offset dxf.plot_origin_x_offset = x_offset * unit_factor # conversion to mm dxf.plot_origin_y_offset = y_offset * unit_factor # conversion to mm dxf.standard_scale_type = standard_scale dxf.unit_factor = 1. / unit_factor # 1/1 for mm; 1/25.4 ... for inch # Setup Layout self.reset_paper_limits() self.reset_extends() self.reset_viewports()