JSCAD User Group

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Newbie question: Write 2D drawing to SVG file?

    General Discussions
    2
    2
    312
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      dburt last edited by

      Hello and thank you for creating and maintaining this very impressive library!
      I'm trying to use V2 for a simple project and am currently stuck on what I'm sure is a very elementary issue.

      I'd like to save an array of rectangles to an SVG file. Originally was hoping to save as PNG, but not sure if this is currently supported?

      Referring to the example on the @jscad/openjscad npm page, is it possible to do something like this:

      const jscad = require("@jscad/openJscad");
      const { rectangle } = require("@jscad/modeling").primitives;
      const fs = require("fs");
      
      const input = rectangle({ center: [0, 0], size: [10, 20] });
      
      const outputData = jscad.generateOutput("svg", input);
      
      fs.writeFileSync("panels.svg", outputData.asBuffer());
      

      Running this code, I get these errors:

      TypeError: cag._toCSGWall is not a function
      at Array.map (<anonymous>)
      at CAG.union
      at convertToSolid2
      at prepareOutput
      at Object.generateOutput
      

      Any tips or guidance on how to accomplish this would be greatly appreciated.

      Thank you in advance!

      z3dev 1 Reply Last reply Reply Quote 0
      • z3dev
        z3dev @dburt last edited by

        @dburt welcome

        Yes. You can make that example work. You might want to take a look at this project, which uses the JSCAD CLI (command line interface) for compiling the design and exporting SVG. Specifically, the 'localfont' project.

        https://github.com/jscad-community/jscad-text

        If you are going to work with other JavaScript libraries, especially those using async functions or promises then take a look at the 'googlefont' project.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Powered by NodeBB | Contributors