4
$\begingroup$

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

```
$\endgroup$

1 Answer 1

7
$\begingroup$

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

$\endgroup$
5
  • $\begingroup$ Don't forget cut=true $\endgroup$ Commented Nov 9, 2022 at 19:01
  • $\begingroup$ I did forget that, yet the result is "acceptable," yes? What is the failure mode of forgetting it? $\endgroup$
    – fred_dot_u
    Commented Nov 9, 2022 at 21:43
  • $\begingroup$ Without cut=true, you get a 2D shadow of the part, not a 2D cut (union of all cuts as Z ranges over -infinity to infinity). $\endgroup$ Commented Nov 9, 2022 at 22:27
  • $\begingroup$ That's useful information. Is there a link to an example model in which both circumstances are provided? $\endgroup$
    – fred_dot_u
    Commented Nov 9, 2022 at 22:54
  • $\begingroup$ In tthe manual I linked to, no? $\endgroup$ Commented Nov 10, 2022 at 0:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .