Newbie question: Write 2D drawing to SVG file?
-
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!
-
@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.