Maker.js, a Microsoft Garage project, is a JavaScript library for creating and sharing modular line drawings for CNC and laser cutters.

View project on GitHub Star

Api - exporter Module

Index

Variables

Private chainLinkToPathDataMap

chainLinkToPathDataMap: IChainLinkToPathDataMap

Private dxfUnit

dxfUnit: object

Type declaration

  • [unitType: string]: number

Private svgPathDataMap

svgPathDataMap: ISvgPathDataMap

svgUnit

Map of MakerJs unit system to SVG unit system

Functions

Private chainToJscadScript

  • chainToJscadScript(chainContext: IChain, facetSize?: number, accuracy?: number): string
  • Parameters

    • chainContext: IChain
    • Optional facetSize: number
    • Optional accuracy: number

    Returns string

chainToSVGPathData

  • chainToSVGPathData(chain: IChain, offset: IPoint, accuracy?: number): string
  • Convert a chain to SVG path data.

    Parameters

    • chain: IChain

      Chain to convert.

    • offset: IPoint

      IPoint relative offset point.

    • Optional accuracy: number

      Optional accuracy of SVG path data.

    Returns string

    String of SVG path data.

Private convert2Dto3D

  • convert2Dto3D<T2D, T3D>(to2D: function, to3D: function, union3D: function, modelToExport: IModel, options?: IJscadCsgOptions): T3D
  • Type parameters

    • T2D

    • T3D

    Parameters

    • to2D: function
    • to3D: function
        • (result2D: T2D, extrude: number, z: number): T3D
        • Parameters

          • result2D: T2D
          • extrude: number
          • z: number

          Returns T3D

    • union3D: function
        • (a: T3D, b: T3D): T3D
        • Parameters

          • a: T3D
          • b: T3D

          Returns T3D

    • modelToExport: IModel
    • Default value options: IJscadCsgOptions = {}

    Returns T3D

Private convertChainsTo2D

Private correctArc

Private exportFromOptionsMap

Private facetSizeToResolution

  • facetSizeToResolution(arcOrCircle: IPathCircle, facetSize: number): number

Private getPathDataByLayer

makeFakeChainFromLoop

Private makePhasedCallback

  • makePhasedCallback(originalCb: IStatusCallback, phaseStart: number, phaseSpan: number): statusCallback

pathToSVGPathData

  • pathToSVGPathData(pathToExport: IPath, pathOffset: IPoint, exportOffset: IPoint, accuracy?: number, clockwiseCircle?: boolean): string
  • Export a path to SVG path data.

    Parameters

    • pathToExport: IPath

      IPath to export.

    • pathOffset: IPoint

      IPoint relative offset of the path object.

    • exportOffset: IPoint

      IPoint relative offset point of the export.

    • Optional accuracy: number

      Optional accuracy of SVG path data.

    • Optional clockwiseCircle: boolean

      Optional flag to use clockwise winding for circles.

    Returns string

    String of SVG path data.

Private startSvgPathData

Private svgArcData

  • svgArcData(d: ISvgPathData, radius: number, endPoint: IPoint, accuracy: number, largeArc?: boolean, increasing?: boolean): void
  • Parameters

    • d: ISvgPathData
    • radius: number
    • endPoint: IPoint
    • accuracy: number
    • Optional largeArc: boolean
    • Optional increasing: boolean

    Returns void

Private svgBezierData

Private svgCircleData

  • svgCircleData(radius: number, accuracy: number, clockwiseCircle?: boolean): ISvgPathData

Private svgCoords

toDXF

  • Renders an item in AutoDesk DFX file format.

    Parameters

    Returns string

    String of DXF content.

  • Renders an item in AutoDesk DFX file format.

    Parameters

    Returns string

    String of DXF content.

  • Renders an item in AutoDesk DFX file format.

    Parameters

    Returns string

    String of DXF content.

toJscadCAG

  • Converts a model to a @jscad/csg object - 2D to 2D.

    Example:

    //First, use npm install @jscad/csg from the command line in your jscad project
    //Create a CAG instance from a model.
    var { CAG } = require('@jscad/csg');
    var model = new makerjs.models.Ellipse(70, 40);
    var cag = makerjs.exporter.toJscadCAG(CAG, model, {maxArcFacet: 1});
    

    Parameters

    • jscadCAG: CAG

      @jscad/csg CAG engine.

    • modelToExport: IModel

      Model object to export.

    • Optional jsCadCagOptions: IJscadCagOptions

    Returns CAG | object

    jscad CAG object in 2D, or a map (keyed by layer id) of jscad CAG objects - if options.byLayers is true.

toJscadCSG

  • Converts a model to a @jscad/csg object - 2D to 3D.

    Example:

    //First, use npm install @jscad/csg from the command line in your jscad project
    //Create a CSG instance from a model.
    var { CAG } = require('@jscad/csg');
    var model = new makerjs.models.Ellipse(70, 40);
    var csg = makerjs.exporter.toJscadCSG(CAG, model, {maxArcFacet: 1, extrude: 10});
    

    Parameters

    • jscadCAG: CAG

      @jscad/csg CAG engine.

    • modelToExport: IModel

      Model object to export.

    • Optional options: IJscadCsgOptions

      Optional options object.

    Returns CSG

    jscad CAG object in 2D, or a map (keyed by layer id) of jscad CAG objects - if options.byLayers is true.

toJscadSTL

  • toJscadSTL(CAG: CAG, stlSerializer: StlSerializer, modelToExport: IModel, options?: IJscadCsgOptions): string | Array<ArrayBuffer>
  • Exports a model in STL format - 2D to 3D.

    Parameters

    • CAG: CAG
    • stlSerializer: StlSerializer

      @jscad/stl-serializer (require('@jscad/stl-serializer')).

    • modelToExport: IModel

      Model object to export.

    • Optional options: IJscadCsgOptions

      Optional options object.

    Returns string | Array<ArrayBuffer>

    String in STL ASCII format.

toJscadScript

  • Creates a string of JavaScript code for execution with a Jscad environment.

    Parameters

    Returns string

    String of JavaScript containing a main() function for Jscad.

toJson

  • Renders an item in JSON.

    Parameters

    • itemToExport: any

      Item to render: may be a path, an array of paths, or a model object.

    • Default value options: IJsonExportOptions = {}

      Rendering options object.

    Returns string

    String of DXF content.

toOpenJsCad

  • DEPRECATED - use .toJscadScript() instead. Creates a string of JavaScript code for execution with the OpenJsCad engine.

    Parameters

    Returns string

    String of JavaScript containing a main() function for OpenJsCad.

  • DEPRECATED - use .toJscadScript() instead. Creates a string of JavaScript code for execution with the OpenJsCad engine.

    Parameters

    Returns string

    String of JavaScript containing a main() function for OpenJsCad.

  • DEPRECATED - use .toJscadScript() instead. Creates a string of JavaScript code for execution with the OpenJsCad engine.

    Parameters

    Returns string

    String of JavaScript containing a main() function for OpenJsCad.

toPDF

  • Injects drawing into a PDFKit document.

    Parameters

    • doc: PDFDocument
    • modelToExport: IModel

      Model object to export.

    • Optional options: IPDFRenderOptions

      Export options object.

    Returns void

    String of PDF file contents.

toSTL

  • DEPRECATED - use .toJscadSTL() instead. Executes a JavaScript string with the OpenJsCad engine - converts 2D to 3D.

    Parameters

    • modelToExport: IModel

      Model object to export.

    • Default value options: IOpenJsCadOptions = {}

      Export options object.

    Returns string

    String of STL format of 3D object.

toSVG

  • Renders an item in SVG markup.

    Parameters

    Returns string

    String of XML / SVG content.

  • Renders an item in SVG markup.

    Parameters

    Returns string

    String of XML / SVG content.

  • Renders an item in SVG markup.

    Parameters

    Returns string

    String of XML / SVG content.

toSVGPathData

  • Convert a model to SVG path data.

    Parameters

    Returns IPathDataByLayerMap | string

    String of SVG path data (if options.byLayers is false) or an object map of path data by layer .

  • Convert a model to SVG path data.

    Parameters

    • modelToExport: IModel

      Model to export.

    • Optional byLayers: boolean

      Optional boolean flag to return a map of path data by layer.

    • Optional origin: IPoint

      Optional origin. Default x = 0, y = topmost y point in the model. Use [0, 0] to use the same origin as Maker.js, which will translate to negative Y values in SVG.

    • Optional accuracy: number

      Optional accuracy of SVG decimals.

    Returns IPathDataByLayerMap | string

    String of SVG path data (if byLayers is false) or an object map of path data by layer .

Private tryGetModelUnits

  • tryGetModelUnits(itemToExport: any): string
  • Try to get the unit system from a model

    Parameters

    • itemToExport: any

    Returns string

Private wrap

  • wrap(prefix: string, content: string, condition: any): string
  • Parameters

    • prefix: string
    • content: string
    • condition: any

    Returns string

Object literals

colors

colors: object

Named colors, safe for CSS and DXF 17 colors from https://www.w3.org/TR/CSS21/syndata.html#value-def-color mapped to DXF equivalent AutoDesk Color Index

aqua

aqua: number

black

black: number

blue

blue: number

fuchsia

fuchsia: number

gray

gray: number

green

green: number

lime

lime: number

maroon

maroon: number

navy

navy: number

olive

olive: number

orange

orange: number

purple

purple: number

red

red: number

silver

silver: number

teal

teal: number

white

white: number

yellow

yellow: number

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc