4

I have created a Mengersponge in OpenScad which is a 3D object. I wanted to get an SVG export from it for the laser cutter but I receive this error:"Current top level object is not a 2D object." How do I select each side of this sponge to export it as SVG for laser cutting?

Code:

module MengerSponge(side = 270, order =3){
    difference(){
        cube([side,side,side],center=true);
        MengerSponge_aux1(side, order);
    }
    }
module MengerSponge_aux1(side, order){
    rotations=[
    [90,0,0],
    [0,90,0],
    [0,0,90],
    ];
    for(rotation=rotations){
        rotate(rotation)
    MengerSponge_aux2(side, order);
        }
}


 module MengerSponge_aux2(side, order){
     if(order>0){
        translate([0,-(side-(side/pow(3,order-1)))/2,0])
            for(i=[0:pow(3,order-1)-1]){
                translate([0,(side/pow(3,order-1))*i,0])
                    translate([-(side-(side/pow(3,order-1)))/2,0,0])
                        for(i=[0:pow(3,order-1)-1]){
                            translate([(side/pow(3,order-1))*i,0,0])
                                cube([(side/pow(3,order)),(side/pow(3,order)),side+1],center=true);
            }
        }
        MengerSponge_aux2(side, order-1);
     }
     else{
         echo("Fail");
     }
 }
side=270;
order=3;
MengerSponge(side, order);

```
bluxixi
  • 43
  • 3

1 Answers1

5

Use the projection() feature of OpenSCAD to effectively generate a plane cut. Position the cube structure in such a manner that the x/y plane intersects the desired shape to be exported. Rendering the code will then generate a 2D image. Previewing the code will generate a 1 mm thick 3D model which will "flatten" when rendered.

For the image below, I did not translate the cube, merely placed the cube generation within the projection feature.

projection(){
MengerSponge(side, order);
}

This rendering will export to SVG as desired. Different positioning of the cube (rotate, translate) will create different patterns.

projection of cube

fred_dot_u
  • 11,420
  • 1
  • 11
  • 24