Bitbybit Docs
    Preparing search index...

    Class Drawing

    Builds drawings as data, for any file format: segments of every kind, paths joined from segments, and parts that put paths on a layer with a color and a line type. io.dxf.dxfCreate writes the parts as DXF and io.svg.svgCreate as SVG; svgToDxf and dxfToSvg convert one file into the other through these parts.

    Index

    Constructors

    • Parameters

      • dxfOf: () => Dxf
      • svgOf: () => Svg

      Returns Drawing

    convert

    • Converts an SVG file into a DXF file, reading it as io.svg.svgRead does and writing it as io.dxf.dxfCreate does.

      Inkscape layers, stroke colors and dash patterns become DXF layers, colors and line types, and curves stay exact. With unit the drawing is read at true size and the DXF states that unit. A drawing too large to write throws.

      Parameters

      • inputs: SvgToDxfDto

        The SVG text, the unit, whether hidden elements are written, and the DXF's color format, version and curve tolerance

      Returns SvgToDxfResultDto

      The DXF text and the reading's warnings

      const converted = bitbybit.io.drawing.svgToDxf({ svg: svgText, unit: Bit.Inputs.Base.unitOfLengthEnum.millimetre });
      const drawing = bitbybit.io.dxf.dxfRead({ dxf: converted.dxf });
    • Converts a DXF file into an SVG file, reading it as io.dxf.dxfRead does and writing it as io.svg.svgCreate does.

      Layers become Inkscape layers and the SVG takes its true size from the unit the DXF states. Splines given only by fit points are left out and named in warnings; a drawing too large to write throws.

      Parameters

      • inputs: DxfToSvgDto

        The DXF file as text or bytes, whether hidden layers are written, and the SVG's line width, border and curve tolerance

      Returns DxfToSvgResultDto

      The SVG text and the reading's warnings

      const converted = bitbybit.io.drawing.dxfToSvg({ dxf: dxfText, includeHiddenLayers: true });
      const drawing = bitbybit.io.svg.svgRead({ svg: converted.svg });

    drawing

    • Makes a circular arc of a drawing path, running counterclockwise about its center from startAngle to endAngle, in degrees, in the XY plane unless a normal tilts it.

      Parameters

      • inputs: DrawingArcSegmentDto

        The center, the radius, the start and end angles and the plane's normal

      Returns DrawingArcSegmentDto

      The arc segment

      const corner = bitbybit.io.drawing.arcSegment({ center: [0, 0], radius: 10, startAngle: 0, endAngle: 90 });
      
    • Makes connected straight segments through points, which bulges can bend into arcs; closed joins the last point back to the first.

      Parameters

      Returns DrawingPolylineSegmentDto

      The polyline segment

      const slot = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [30, 0], [30, 10], [0, 10]], closed: true, bulges: [0, 1, 0, 1] });
      
    • Makes a B-spline or NURBS curve of a drawing path from its control points and degree, with its knots and weights when they are given.

      Parameters

      Returns DrawingSplineSegmentDto

      The spline segment

      const wave = bitbybit.io.drawing.splineSegment({ controlPoints: [[0, 0], [10, 8], [20, -8], [30, 0]], degree: 3 });
      
    • Makes an ellipse, or an arc of one, for a drawing path.

      The ellipse is given by its center, the vector to the end of its major axis and the minor to major ratio; parameters in radians pick the arc, running counterclockwise about the normal.

      Parameters

      • inputs: DrawingEllipseSegmentDto

        The center, the major axis, the ratio, the start and end parameters and the plane's normal

      Returns DrawingEllipseSegmentDto

      The ellipse segment

      const lens = bitbybit.io.drawing.ellipseSegment({ center: [0, 0], majorAxis: [20, 0], ratio: 0.5, startParameter: 0, endParameter: Math.PI });
      
    • Joins segments into one path, drawn in order like the edges of a wire; segments that meet are drawn as one stroke in SVG.

      Parameters

      Returns DrawingPathDto

      The path

      const edge = bitbybit.io.drawing.lineSegment({ start: [0, 0], end: [40, 0] });
      const corner = bitbybit.io.drawing.arcSegment({ center: [40, 10], radius: 10, startAngle: 270, endAngle: 360 });
      const outline = bitbybit.io.drawing.path({ segments: [edge, corner] });
    • Puts paths on a named layer with a color and a line type, making one part of a drawing.

      A drawing may hold several parts; io.dxf.dxfCreate writes them as DXF and io.svg.svgCreate as SVG.

      Parameters

      • inputs: DrawingPartDto

        The layer name, the color, the paths and the line type

      Returns DrawingPartDto

      The part

      const square = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [40, 0], [40, 30], [0, 30]], closed: true });
      const cut = bitbybit.io.drawing.part({ layer: "cut", color: "#ff0000", paths: [{ segments: [square] }] });