JSCAD User Group
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Newbie question: Write 2D drawing to SVG file?

    Scheduled Pinned Locked Moved General Discussions
    2 Posts 2 Posters 838 Views 1 Watching
    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 Offline
      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!

      z3devZ 1 Reply Last reply Reply Quote 0
      • z3devZ Offline
        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

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post
        Powered by NodeBB | Contributors