def set_current_lineweight(doc: "Drawing", lineweight: int): """Set current lineweight, see :ref:`lineweights` reference for valid values. """ if not validator.is_valid_lineweight(lineweight): raise const.DXFValueError(f'invalid lineweight value: "{lineweight}"') doc.header[CURRENT_LINEWEIGHT] = lineweight
def test_is_valid_lineweight(): assert is_valid_lineweight(0) is True assert is_valid_lineweight(50) is True assert is_valid_lineweight(211) is True assert is_valid_lineweight(-4) is False, 'is too small' assert is_valid_lineweight(212) is False, 'is too big' assert is_valid_lineweight(10) is False
def add( self, name: str, *, color: int = const.BYLAYER, true_color: int = None, linetype: str = "Continuous", lineweight: int = const.LINEWEIGHT_BYLAYER, plot: bool = True, transparency: Optional[float] = None, dxfattribs: Dict = None, ) -> "Layer": """Add a new :class:`~ezdxf.entities.Layer`. Args: name (str): layer name color (int): :ref:`ACI` value, default is BYLAYER true_color (int): true color value, use :func:`ezdxf.rgb2int` to create ``int`` values from RGB values linetype (str): line type name, default is "Continuous" lineweight (int): line weight, default is BYLAYER plot (bool): plot layer as bool, default is ``True`` transparency: transparency value in the range [0, 1], where 1 is 100% transparent and 0 is opaque dxfattribs (dict): additional DXF attributes .. versionadded:: 0.17 """ dxfattribs = dict(dxfattribs or {}) if validator.is_valid_aci_color(color): dxfattribs["color"] = color else: raise const.DXFValueError(f"invalid color: {color}") dxfattribs["linetype"] = linetype if validator.is_valid_lineweight(lineweight): dxfattribs["lineweight"] = lineweight else: raise const.DXFValueError(f"invalid lineweight: {lineweight}") if true_color is not None: dxfattribs["true_color"] = int(true_color) dxfattribs["plot"] = int(plot) layer = cast("Layer", self.new(name, dxfattribs)) if transparency is not None: layer.transparency = transparency return layer
def is_valid_layer_lineweight(lw: int) -> bool: if validator.is_valid_lineweight(lw): if lw not in (LINEWEIGHT_BYLAYER, LINEWEIGHT_BYBLOCK): return True return False
def lineweight(self, value: int): if validator.is_valid_lineweight(value): self._lineweight = value else: raise const.DXFValueError(f"invalid lineweight value '{value}'")