I can't get my text cutout to work

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

I can't get my text cutout to work

andersjoensson
Hey everybody
I am in my first week of Openscad, hope you will help me in the right
direction.

I think I may have made a mess of my project, but I hope you can see what I
did wrong.

My difference() text cutout on one arm of my project is not working properly
- its not really cutting away any material, but seems like a "shadow"
instead on the preview...
Does it mean that my cutout is working? I have done several other text
cutouts without problems, maybe its because its a mirrored part?

I know most of my code should be cleaned up, but my project goes haywire
every time I change something at this point, and I really just want a rough
prototype for printing.

Best
Anders

My project (the part in bold should be my problem):

-------------------------------------------------------------------------------------------------------------------

//rotering af urholder til print:
rotate([90,150,0]){
//rundt rør
rotate([0,0,60]){
difference(){
cylinder(h=45, r=26, center=true, $fn=150);
cylinder(h=41, r=23, center=true, $fn=80);
translate([22,0,0]){
    rotate([0,90,0])cube([46,40,9], center=true);}}
translate([16,0,0]){
    rotate([0,90,0])cube([45,38,3], center=true);}
}
//venstre fod

difference(){
translate([0,-33,30]){
rotate(a=45, v=[1,0,0]){ cube([34,3,50],center=true);
}}
//trækker indersiden af cylinder fra
cylinder(h=45, r=24, center=true, $fn=80);
//hul til snor til rorline
translate([8,-30,30]){
rotate([-45,0,0]){    cylinder(h = 10, r=2, center = true, $fn=60);}}
//trækker skrå sider på fod fra
translate([8,-52,0]){
rotate(a=-15,v=[0,0,1]){ cube([55,55,55]);
}}
mirror([1,0,0]){
translate([8,-52,0]){
rotate(a=-15,v=[0,0,1]){ cube([55,55,55]);
}}}
}
//højre fod

*mirror([0,0,1]){
difference(){
translate([0,-33,30]){
rotate(a=45, v=[1,0,0]){
cube([34,3,50],center=true);
//Navn i urholder
rotate([0,-90,90]){
translate([-8,-5,-10]){
linear_extrude(height=20){
text("NBL", $fn=150);}}
}}}
///trækker indersiden af cylinder fra
cylinder(h=45, r=24, center=true, $fn=80);
///trækker skrå sider på fod fra
translate([8,-52,0]){
rotate(a=-15,v=[0,0,1]){ cube([55,55,55]);}}
mirror([1,0,0]){
translate([8,-52,0]){
rotate(a=-15,v=[0,0,1]){ cube([55,55,55]);
    }}}
    }}*
    //bagerste fod
   
difference(){
translate([-30,-23,0]){
rotate(a=20, v=[0,0,1]){ cube([50,3,45],center=true);
}}
//trækker hul til urrem fra
rotate([0,-90,45]){
cylinder(h=62, r1=23, r2=14, center=true, $fn=80);}
//trækker indersiden af cylinder fra
cylinder(h=46, r=23, center=true, $fn=80);
///trækker skrå sider på fod fra
    translate([-47,-28,-43]){
rotate(a=-15,v=[0,-1,0]){ cube([55,55,55], center=true);}}
mirror([0,0,1]){
    translate([-47,-28,-43]){
rotate(a=-15,v=[0,-1,0]){ cube([55,55,55], center=true);}}}
}
//platform til sugekop h
difference(){
translate([0,-52,54]){
rotate(a=10,v=[1,0,0]){
cube([17,3,15], center=true);}}
translate([0,0,55]){
rotate([90,0,0]){
cylinder(h=120, r=2.5, center=true, $fn=200);}}
    }
//platform til sugekop v
mirror([0,0,1]){
difference(){
translate([0,-52,54]){
rotate(a=10,v=[1,0,0]){
cube([17,3,15], center=true);}}
translate([0,0,55]){
rotate([90,0,0]){
cylinder(h=120, r=2.5, center=true, $fn=200);}}
    }}
//platform til sugekop bag
difference(){
translate([-60,-31.5,0]){
cube([17,3,26], center=true);}  
    translate([-61,0,0]){
rotate([90,0,0]){
cylinder(h=120, r=2.5, center=true, $fn=200);}}
}
}



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: I can't get my text cutout to work

JordanBrown
[ For anybody else:  the * in front of the mirror() invocation is the forum software saying "bold". ]

I think you're having two problems:
  • I think that one of the things you're seeing is rendering problems in the previewer.  Does it look different if you do F6 instead of F5?  Fix this by adding "convexity=10" to your linear_extrude().
  • What I see is a straightforward extrusion, not a difference / cutout.
Let's apply some indentation:
mirror([0,0,1]){
   difference(){
      translate([0,-33,30]){
         rotate(a=45, v=[1,0,0]){ 
            cube([34,3,50],center=true);
            //Navn i urholder
            rotate([0,-90,90]){
               translate([-8,-5,-10]){
                  linear_extrude(height=20, convexity=10){
                     text("NBL", $fn=150);
                  }
               }
            }
         }
      }
      ///trækker indersiden af cylinder fra
      cylinder(h=45, r=24, center=true, $fn=80);
      ///trækker skrå sider på fod fra
      translate([8,-52,0]){
         rotate(a=-15,v=[0,0,1]){
            cube([55,55,55]);
         }
      }
      mirror([1,0,0]){
         translate([8,-52,0]){
            rotate(a=-15,v=[0,0,1]){
               cube([55,55,55]);
            }
         }
      }
   }
}
//bagerste fod

Now the problem becomes more apparent.  You have a cube and the text, minus a cylinder, minus two cubes.

Option 1:  add in another difference():
mirror([0,0,1]){
    difference(){
        translate([0,-33,30]){
            rotate(a=45, v=[1,0,0]){ 
                difference() {			// NEW
                    cube([34,3,50],center=true);
                    //Navn i urholder
                    rotate([0,-90,90]){
                        translate([-8,-5,-10]){
                            linear_extrude(height=20, convexity=10){
                                text("NBL", $fn=150);
                            }
                        }
                    }
                }
            }
        }
        ///trækker indersiden af cylinder fra
        cylinder(h=45, r=24, center=true, $fn=80);
        ///trækker skrå sider på fod fra
        translate([8,-52,0]){
            rotate(a=-15,v=[0,0,1]){
                cube([55,55,55]);
            }
        }
        mirror([1,0,0]){
            translate([8,-52,0]){
                rotate(a=-15,v=[0,0,1]){
                    cube([55,55,55]);
                }
            }
        }
    }
}
//bagerste fod

Option 2:  Move the text out to be a child of the original difference() (and duplicate the transformations):

mirror([0,0,1]){
    difference(){
        translate([0,-33,30]){
            rotate(a=45, v=[1,0,0]){ 
                cube([34,3,50],center=true);
            }
        }
        translate([0,-33,30]){		// COPIED
            rotate(a=45, v=[1,0,0]){ 
                //Navn i urholder
                rotate([0,-90,90]){	// MOVED
                    translate([-8,-5,-10]){
                        linear_extrude(height=20, convexity=10){
                            text("NBL", $fn=150);
                        }
                    }
                }
            }
        }
        ///trækker indersiden af cylinder fra
        cylinder(h=45, r=24, center=true, $fn=80);
        ///trækker skrå sider på fod fra
        translate([8,-52,0]){
            rotate(a=-15,v=[0,0,1]){
                cube([55,55,55]);
            }
        }
        mirror([1,0,0]){
            translate([8,-52,0]){
                rotate(a=-15,v=[0,0,1]){
                    cube([55,55,55]);
                }
            }
        }
    }
}
//bagerste fod



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: I can't get my text cutout to work

andersjoensson
Thank you so much. (:

I ended up adding an extra difference and it looks great! Added a cube to
hold the 2 floating pieces in my B. But i don't really get how it makes a
difference, as you only moved it below my translate and rotate? Is there a
maximum of how many elements i can subtract with difference?

I guess I am just being blinded by my own hideous code. :-)

Best



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: I can't get my text cutout to work

JordanBrown
On 5/31/2018 12:46 AM, andersjoensson wrote:
Thank you so much. (:

Glad to be of assistance.
I ended up adding an extra difference and it looks great! Added a cube to
hold the 2 floating pieces in my B.

Or just don't have it punch all the way through.

But i don't really get how it makes a
difference, as you only moved it below my translate and rotate? Is there a
maximum of how many elements i can subtract with difference?

No, but look at the indentation.

When you say
difference() {
    A;
    B;
    C;
    ...
}
you are asking for A, subtract B, subtract C.  Each of A, B, and C can be arbitrarily complex.

Here's what you had written:
difference(){
    translate([0,-33,30]){
        rotate(a=45, v=[1,0,0]){ 
            cube([34,3,50],center=true);
            //Navn i urholder
            rotate([0,-90,90]){
                translate([-8,-5,-10]){
                    linear_extrude(height=20, convexity=10){
                        text("NBL", $fn=150);
                    }
                }
            }
        }
    }
    ///trækker indersiden af cylinder fra
    cylinder(h=45, r=24, center=true, $fn=80);
    ...

That entire "translate" block is the A in the difference operation.  The first thing being subtracted from the object, the B in the difference, is the cylinder.  You're saying something like (ignoring translates and rotates)

(cube plus text) minus cylinder minus cube minus cube

My "option 1", adding in another difference(), makes it be

(cube minus text) minus cylinder minus cube minus cube

and my "option 2", pulling the text out, makes it be

cube minus text minus cylinder minus cube minus cube

I guess I am just being blinded by my own hideous code. :-)

Indentation is your friend.  Be obsessive about it.


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org