JSCAD User Group

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

    Why am I getting "Uncaught TypeError: CSG.Path2d is not a constructor"?

    General Discussions
    3
    5
    680
    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.
    • wildjerry
      wildjerry last edited by wildjerry

      I'm new to both Open(J)Scad and javascript in general, and I keep getting this error.

      Uncaught TypeError: CSG.Path2d is not a constructor
      Line: 97,col: 9
      (blob:https://openjscad.org/f3af8c9b-afdd-46ee-ad07-40d1f04dd681)
      

      My code is intended to create an array of 2d shapes, then render them in either 2d or 3d(using a revolve extrude) with a union().

      function main(params) {
          
          sketches = [
              square([10,2]), 
              square([3,20]),
              new CSG.Path2d([
                  [0,0],
                  [0,9],
                  [19,0],
                  ],true),
              ];
          return render(sketches,params.dimension);
      }
      
      function getParameterDefinitions() {
          return [
              { name: 'dimension', type: 'checkbox', checked: false, caption: 'render in 3d?' }, 
          ];
      }
      
      function render(obj,dim) {
              if (dim){
              extrudes =[];
              for (var i of obj){
                  extrudes.push(rotate_extrude(i));
              }
              return union(extrudes);
          } else {
              return union(sketches);
          }
      }
      
      z3dev 1 Reply Last reply Reply Quote 0
      • gilboonet
        gilboonet @wildjerry last edited by

        V1 color syntax is color("Red", extrudes[0])

        1 Reply Last reply Reply Quote 0
        • wildjerry
          wildjerry last edited by

          Related Noob Question: I'm trying to add color to my script, and I'm getting this error:

          Uncaught TypeError: object.setColor is not a function
          Line: 6919,col: 17
          

          My current code is:

          function main(params) {
              
              sketches = [
                  square([10,2]), 
                  square([3,10]),
                  new polygon([
                      [0,0],
                      [9,0],
                      [3,9],
                      ],true),
                  ];
                  
              
              return render(sketches,params.dimension);
          }
          
          function getParameterDefinitions() {
              return [
                  { name: 'dimension', type: 'checkbox', checked: false, caption: 'render in 3d?' },
              ];
          }
          
          function render(obj,dim,colors) {
              if (dim){
                  extrudes =[];
                  for (var i of obj){
                      extrudes.push(rotate_extrude(i));
                  }
                  
                  extrudes[0]=color(extrudes[0],"Red")
                  extrudes[1]=color(extrudes[1],"Red")
                  extrudes[2]=color(extrudes[2],"White")
                  
                  return union(extrudes);
              }
              else {
                  return union(sketches);
              }
          }
          

          The only difference between the fixed version of the code and this one is the added colors after I extrude. Based on the documentation, I don't see why this doesn't work.

          gilboonet 1 Reply Last reply Reply Quote 0
          • wildjerry
            wildjerry last edited by

            Thank You!

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

              @wildjerry Cool name! Welcome.

              OK. You just need to change Path2d to Path2D.

              However... V1 JSCAD cannot render paths. So, you should use something like this for 2D shapes.

              let p1 = polygon([ [0,0],[3,0],[3,3] ])
              

              Now, that should get you moving.

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