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

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

    Scheduled Pinned Locked Moved General Discussions
    5 Posts 3 Posters 1.6k Views 2 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.
    • wildjerryW Offline
      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);
          }
      }
      
      z3devZ 1 Reply Last reply Reply Quote 0
      • z3devZ Offline
        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
        • wildjerryW Offline
          wildjerry
          last edited by

          Thank You!

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

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

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

              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