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



  • 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);
        }
    }
    


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



  • 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.



  • Thank You!



  • @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.


Log in to reply