Esempio n. 1
0
    def add_linear_dim(self,
                       base: 'Vertex',
                       p1: 'Vertex',
                       p2: 'Vertex',
                       location: 'Vertex' = None,
                       text: str = "<>",
                       angle: float = 0,  # 0=horizontal, 90=vertical, else=rotated
                       text_rotation: float = None,
                       dimstyle: str = 'EZDXF',
                       override: dict = None,
                       dxfattribs: dict = None) -> DimStyleOverride:
        """
        Add horizontal, vertical and rotated dimension line. If an :class:`UCS` is used for dimension line rendering,
        all point definitions in UCS coordinates, translation into :ref:`WCS` and :ref:`OCS` is done by the rendering
        function. Manual set extrusion vector will be replaced by OCS defined by UCS or (0, 0, 1) if no UCS is used.

        This method returns a :class:`DimStyleOverride` object, to create the necessary dimension geometry, you have to
        call :meth:`DimStyleOverride.render` manually, this two step process allows additional processing steps on the
        :class:`Dimension` entity between creation and rendering.

        Args:
            base: location of dimension line, any point on the dimension line or its extension will do (in UCS)
            p1: measurement point 1 and start point of extension line 1 (in UCS)
            p2: measurement point 2 and start point of extension line 2 (in UCS)
            location: user defined location for text mid point (in UCS)
            text: None or "<>" the measurement is drawn as text, " " (one space) suppresses the dimension text,
                  everything else `text` is drawn as dimension text
            dimstyle: dimension style name (:class:`DimStyle` table entry), default is "EZDXF"
            angle: angle from ucs/wcs x-axis to dimension line in degrees
            text_rotation: rotation angle of the dimension text away from its default orientation
                           (the direction of the dimension line) in degrees
            override: :class:`DimStyleOverride` attributes
            dxfattribs: DXF attributes for :class:`Dimension` entity

        Returns: :class:`DimStyleOverride`

        """
        type_ = {'dimtype': const.DIM_LINEAR | const.DIM_BLOCK_EXCLUSIVE}
        dimline = cast('Dimension', self.build_and_add_entity('DIMENSION', dxfattribs=type_).cast())
        dxfattribs = copy_attribs(dxfattribs)
        dxfattribs['dimstyle'] = dimstyle
        dxfattribs['defpoint'] = Vector(base)
        dxfattribs['text'] = text
        dxfattribs['defpoint2'] = Vector(p1)
        dxfattribs['defpoint3'] = Vector(p2)
        dxfattribs['angle'] = float(angle)
        # text_rotation ALWAYS overrides implicit angles as absolute angle (0 is horizontal)!
        if text_rotation is not None:
            dxfattribs['text_rotation'] = float(text_rotation)
        dimline.update_dxf_attribs(dxfattribs)

        style = DimStyleOverride(dimline, override=override)
        if location is not None:
            style.set_location(location, leader=False, relative=False)
        return style
Esempio n. 2
0
 def add_ordinate_dim(self, override: dict = None, dxfattribs: dict = None) -> DimStyleOverride:
     type_ = {'dimtype': const.DIM_ORDINATE | const.DIM_BLOCK_EXCLUSIVE}
     dimline = cast('Dimension', self.build_and_add_entity('DIMENSION', dxfattribs=type_).cast())
     dxfattribs = copy_attribs(dxfattribs)
     dimline.update_dxf_attribs(dxfattribs)
     style = DimStyleOverride(dimline, override=override)
     return style