/r/openscad

Photograph via snooOG

Share news, tips and tricks, and ask questions about how to use 3D CAD modelers for programmers, such as OpenSCAD, CoffeeSCAD, and ImplicitCAD

Quick Links

/r/openscad

4,598 Subscribers

1

Building a PC to run OpenSCAD smoothly

I am currently using OpenSCAD on a workstation with Xeon E5-2660V2 (3rd gen Intel, 10 cores, 20 threads, 2.2 Ghz), 32 Gb DDR3-1333 RAM and RX 550 4 Gb GDDR5 (if you are wondering, that takes 2U in a rack, and I am running Fedora Linux). It's mostly fine, but it feels like not a perfect fit for OpenSCAD, and some larger models take pretty long time to preview, and very long time to render. As I understand, this limitation comes mostly from the fact that the render code is not paralleled and is not taking advantage of all 20 threads that the CPU provides.

So I am thinking of building a desktop computer (probably something much smaller than 2U) which would not struggle with such tasks. Am I getting it right, that the most important parameter for OpenSCAD is single thread performance? I think 32 Gb RAM is still plenty, and the GPU is not that important as long as it supports OpenGL.

Since I have the budget, I decided to compile the most powerful config that I could think of. And since I am on Linux, I decided to go with Intel GPU. The config is i7-11700f (or i9-11900f) on a H510-based motherboard, 32 Gb DDR4-3200 RAM and A770 16 Gb GDDR6. Do you think that would be an overkill?

Alternatively, I can get an newest 14th gen Intel i9-14900 with integrated GPU, and take advantage of DDR5 memory speed. I can also get an ATX12VO motherboard and PSU for it which I think is cool. Which option do you think is better?

12 Comments
2024/04/11
07:52 UTC

0

Code help

Hey Guys I have some code that I need some help so that the inside of my light box has no walls between letters in the box.

4 Comments
2024/04/10
11:11 UTC

2

Colors in render

I want to color certain elements of my design so that I can visualise them better. Unfortunately when I render my design, the colours don’t show. Preview however is too imprecise with a lot of artifacts. Is there a solution to this?

16 Comments
2024/04/08
19:30 UTC

1

Pinhole plate for eclipse projection

I printed the following pinhole plate. You hold it a few feet above a flat concrete surface and let the sunlight pass through the plate onto concrete. During ordinary days the projections are circles of sunlight. As the eclipse progresses you get crescents.

// radius of hole.
rad=1; // [0.1:0.1:100]
// thickness of card
wall=1.5; // [0.1:0.1:100]

// nGon -
module nGon(r=20){
  circle(r=r,$fn=36);
}

module nGonGrid(r=20, wall=2, x=5, y=4){
  for(i=[0:x-1], j=[0:y-1]) {
    translate([10*(sqrt(3)*r*i + ((j%2)*sqrt(3)/2*r)),10*1.5*r*j]){
      // color((0==(((i+1)*(j+1))%18))?"yellow":"red") // DEBUG
      nGon(rad);
    }
  }
}

linear_extrude(wall)difference(){
  square([180,180]);
  translate([30, 30])nGonGrid(r=2, wall=2, x=4, y=5);
}
0 Comments
2024/04/08
06:42 UTC

0

Generate OpenSCAD with AI

Can GenAI models generate OpenSCAD scripts? Yes, but… Conditions apply. See below the visual comparison of outputs produced by Gemini and ChatGPT. Both the image and the text were provided to the models.

Here are the steps to play with both Gemini and ChatGPT while observing the produced 3D models interactively:

  • Install the PartCAD extension for Visual Studio Code
  • Open settings to configure Google and OpenAI API keys
  • Switch to the PartCAD workbench
  • Click “Create Package”
  • Click “Generate a CAD model with AI”
  • Select OpenSCAD or CadQuery
  • Enter a description of the object you want to generate
  • See progress in the terminal view at the bottom
  • Inspect the generated 3D model in the view on the right
  • Change the prompt on the left and click “Generate”
  • For better observability, change the verbosity settings

All hands on deck for creating an AI-powered open-source CAD and PLM framework! Whether you want to practice more prompt engineering or improve part generation in PartCAD, install PartCAD and tweak the prompts and chaining it uses to generate the models:

  • $ git clone https://github.com/openvmp/partcad
  • # Switch to the Python environment used in VS Code
  • $ pip install -U -e ./partcad/partcad -e ./partcad/partcad-cli
  • # Edit partcad/src/partcad/part_factory_feature_ai.py

#openscad #cadquery #genai #gemini #chatgpt #plm

Generate OpenSCAD with AI

4 Comments
2024/04/08
03:02 UTC

3

TIP: How to extrude a sketch in OpenSCAD with BOSL2

A common issue with OpenSCAD is that the notion of sketches is missing, probably because it isn't really the "OpenSCAD way". We might still want to extrude or pad a 2D sketch into 3D. Of course this is just as easily accomplished with boolean operations directly on 3D solids. However, applying fillets and chamfers to the result can be a nightmare, even with the help of BOSL2.

Here's a way to do this using BOSL2's Regions, at least for chamfers. Round-overs don't work yet. Hopefully this is helpful to somebody.

include <BOSL2/std.scad>
include <BOSL2/rounding.scad>

$fn = 32;

mouse = union(
    [
        move([-4.5,4.5], circle(d=5)),
        move([4.5,4.5], circle(d=5)),
        circle(d=10),
    ]
);

rgn = difference(
    [
        square(50, center=true),
        move([15,15], circle(d=10)),
        move([-15,-15], circle(d=10)),
        move([0,25], square(10, center=true)),
        zrot(45, square([1, 100], center=true)),
        mouse
    ]
);
    
module offset_sweep_region(rgn, height, top, top_hole, bottom, bottom_hole) {

    connected_regions = region_parts(rgn);
    for(c_rgn = connected_regions) {
        num_holes = len(c_rgn)-1;
        difference() {
            offset_sweep(c_rgn[0], height=height, bottom=bottom, top=top, steps=15);
            
            if(num_holes > 0)
                for(i=[1:num_holes]) 
                    offset_sweep(c_rgn[i], height=height, bottom=bottom_hole, top=top_hole, steps=15);
        }
    }
}


left(30) rainbow(rgn) stroke($item, width=.25,closed=true);

profile_outside = os_chamfer(width=1);
profile_inside = os_chamfer(width=-1);
right(30) offset_sweep_region(rgn, height=5, top=profile_outside, bottom=profile_outside, top_hole=profile_inside, bottom_hole=profile_inside);

Extrude operation performed on BOSL2 regions in OpenSCAD

0 Comments
2024/04/07
23:10 UTC

17

Use and abuse of modules for parametric robot arms :)

15 Comments
2024/04/07
20:54 UTC

2

Cutout at an angle?

I'm essentially looking for an angled cutout.
I have this

https://preview.redd.it/h1ejfzoxx2tc1.png?width=794&format=png&auto=webp&s=cb80a33c0a8956f08608a9f4c38c595eb0249f1a

and i want to remove the red part..

https://preview.redd.it/byj4af55y2tc1.png?width=840&format=png&auto=webp&s=e8d1eb29e7663db58ce20cecd2482dd3f385936a

assuming that the right edge of the red part is $edge_width, the top is $edge_height and the current cutout is $cutout_depth mm deep, and i'm happy with the angle being 45 degrees - is there an easy solution to do so?

5 Comments
2024/04/07
16:00 UTC

0

help finding parse error

New to openscad, so probably something dumb. I'm getting an error on the sphere declare, it's highlighted red after the =

// Size of the egg
size = 50;

// Smooth sphere function

sphere(r) = {
    r * cos(theta) * sin(phi);
    r * sin(theta) * sin(phi);
    r * cos(phi);
}

11 Comments
2024/04/07
08:22 UTC

6

2021.1 latest version, but lots of updates have been added in the meantime

Why have there not been any new releases? All platforms have the same old version, even though there have been many fixes. Are we getting any new versions, are do people need to build it from source? Kind of wondering what´'s going on here..

18 Comments
2024/04/03
08:27 UTC

2

How do you carve out a partial cylindrical shape from a surface?

Hey newbie here to this and trying to build a small little car hauler for my Hot Wheels and need to add an indentation to the bed/surface so the cars dont roll off.

This is the code I have thus far for the entire project.

cube([26,13,2],center=true);
 translate([12,0,4])
    cube([2,13,6], center=true);
 translate([0,-6,1])
    cube([26,1,1], center=true);
 translate([0,6,1])
    cube([26,1,1], center=true);
$fn=90;
rotate([135,90,45])
    translate([-3.5,5,.75])
        cylinder(r=4,h=4);

Here's what it looks like at the moment, and what I want to do is cut the cylinder part touching the bed out from the bed and leave a nice tire holder indent. Would any one be able to lend a hand here and point me in the right direction?

https://preview.redd.it/082bqs6u14sc1.png?width=3006&format=png&auto=webp&s=fc41c7eb8d48f93a4990ff8c7cf5f778156de3d5

5 Comments
2024/04/02
18:38 UTC

4

Importing values from CSV file for use in openscad program?

Hi, I have a csv file with a bunch of values I want to use in an openscad project. What's the best way to automatically grab those values (rather than copying/pasting them in.)

I googled around for a while and it doesn't seem like OpenSCAD can iterate through csv files? That's... essentially what I'm looking for.

I want it done automatically because there are TONS of different csv files (which I generate using a different program.)

I can change the format of the CSV file if necessary. I could output JUST the values I need instead of the entire CSV file, whatever is easiest.

I'm basically using it to generate a cam for a sewing machine, and these cams have different positions, and these positions are in a CSV file generated from another program I've written (in Python).

Thanks!

EDIT: I could also export radial coordinates (distance + angle) (which are essentially vectors) if necessary.

EDIT2: I suppose I could LITERALLY export an entire openscad... program using python. But that seems a bit overkill.

6 Comments
2024/04/02
17:06 UTC

3

Trouble with the curve

This is my first attempt at CAD of any type,. I am trying to recreate a scale foot, but I am having trouble. I am trying to form a concave up shape on the surface that is supposed to contact the carpet, but the whole cone ends up holo. I am not sure what I am missing.

$fn = 500;

difference(){

cylinder(h = 10, r=21.25);

translate([0, 0, 7.5])cylinder(h = 2.5, r=19.65);

translate([0,0,5]) cylinder(h = 5, r = 9);

cylinder(h = 3.5, r=21.25);

}

difference(){

cylinder(h = 3.5, r1 = 8.8, r2 = 21.25);

translate([0,0,18.1]) sphere(r=20);

}

https://preview.redd.it/ztsaujfkssrc1.png?width=2186&format=png&auto=webp&s=64b183090a08c0c16d7f90e93396ede54c3d879e

https://preview.redd.it/1embj24ossrc1.png?width=1797&format=png&auto=webp&s=0ac53779da3d6f112e5b3157845d0f017bec7b51

8 Comments
2024/04/01
04:46 UTC

5

Resolution

Another resolution question :) I use the following: $fn = $preview ? 32 : 128; at the top of my files. What's the max resolution I can set this for a 3D printer? Even if the slicing software has it's limits, what's a realistic expectation? Which mechanical traits does it depend on?

14 Comments
2024/03/31
02:49 UTC

2

Bisecting/splitting a model to fit on bed

Hi all I am completely new to 3d printing. I am using an scad I found on printables and modified to fit my needs, which is a solar film cover for my telescope. I am using a 3d printer I have at work, which is an ultimaker s5. I am using OpenSCAD and Cura. SCAD code and image for example below.

My question is; what is the easiest way to to bisect my model or maybe break it up into 4? Even with the large printer I have access to it doesn't quite fit. I just tried my first print having the slice angled up with supports but I just abandoned it as something clearly went wrong, also posted below. I just made another slice tweaking some settings and using the tree support but we will see how that looks in the morning.

I tried using Banana split to do it but the problem is that basically just mirrors what is displayed under the plate so while I have two half circles they are straight up still requiring supports, instead of flat. And you can only do that once so any more than a bisect is out.

I would really prefer this to be one piece but if I have to split it and then find a way to connect the pieces after then so be it. Either way I should probably learn how to do it. I've started some cursory googling and so far did find something involving cubes and transforms and I will fiddle with that when I get a chance but wanted to get this out in the ether in case some gurus know of better ways.

Bonus question, if anyone knows of an easy way to modify the split pieces in a way to make them lock together so I don't have to glue or use some bracketing on the fairly thin flange to hold it all together, that'd be great.

thanks.

include <BOSL2/std.scad>

$slop=0.15;
$fa=1;
$fs=$preview ? 2 : 0.5;

// parameterization here
od=240;  // outer diameter of telescope
lh=30; // lip height
wall=2; // wall thickness
io=25; // inner overlap hcnaged from 9 to 25

module bottom() {
    tube(id=od-2*io, wall=wall+io, h=wall, anchor=BOTTOM) {
        position(TOP) tube(id=od, wall=wall, h=lh, anchor=BOTTOM);
        position(BOTTOM)
        rot_copies(n=8)
        rotate_extrude(angle=10) left((od)/2+wall) rotate(90) trapezoid(h=wall, w2=wall*0.5, ang=[90, 45], anchor=BOTTOM+LEFT);
    }
}

module top() {
    tube(od=od+6*wall+2, id=od-2*io, h=wall, anchor=TOP) {
        diff() {
            position(TOP) tube(od=od+6*wall+2, id=od+1+2*wall, h=lh/2, anchor=BOTTOM);
            rot_copies(n=8)
            tag("remove")
            {
                rotate_extrude(angle=11) left((od)/2+wall+0.499) up(wall) square([wall, lh], anchor=BOTTOM+RIGHT);
                poly = [[-0.01,-0.01], [0,2*wall], [wall, wall], [wall, 0]];
                spiral_sweep(poly, h=wall, d=od+1+2*wall, turns=0.06, spin=-16);
            }
        }
    }
}

module cover() {
    let(d=od+7*wall+3.5, t=wall/2, h=5) {
        cyl(d=d, h=t, anchor=TOP) {
            position(TOP) tube(od=d, wall=t, h=h, anchor=BOTTOM);
        }
    }
}

module storage_cover() {
    let(d=od+3*wall, t=wall/2, h=5) {
        cyl(d=d, h=t, anchor=TOP) {
            position(TOP) tube(od=d, wall=t, h=h, anchor=BOTTOM);
        }
    }
}

bottom();

left(od*1.2) top();

right(od*1.2) cover();

fwd(od*1.2) storage_cover();

https://preview.redd.it/qtxmjy3zfirc1.png?width=1307&format=png&auto=webp&s=60d92e170f4db1a602e7d08362a130975098a404

https://preview.redd.it/9g331o40girc1.png?width=1500&format=png&auto=webp&s=affb8aa69353ff31c29175e6a419ed3ec92fee44

9 Comments
2024/03/30
17:57 UTC

16

I needed a template for an elliptical corner contour. OpenSCAD to the rescue! [CIC]

10 Comments
2024/03/28
00:24 UTC

6

Luggage Tag

I am 3D printing g a luggage tag and I have all the info on the front but how do I add an image to the back ? The original file was from Thingverse that could be customized. I want to add my son’s High School Marching Band Logo

4 Comments
2024/03/26
04:50 UTC

11

I want to start using openscad

Ive never done 3d modelling in my life, and nothing near it either. i have taken a small interest in 3d modeling and printing now and wonder, how do i start? any tips?

15 Comments
2024/03/22
09:20 UTC

2

can only generate one part of my model, why?

// there's something basic i'm not getting.

//my math is checked, all my measurements are correct but after generating the core part

// i cant add anything to it:

$fa = 1;

$fs = 0.1;

module slantedprism(s,z, slant,center){ // example uses 10,10, 10.55

// s is base leg

// z is how tall it is

// slant is the slope of the face center

c=s/2;

ha=s*sqrt(3.0)/2.0; // =8.66

yoff=s*tan(slant); // calculated from the 10.55angle =1.86

xoff=yoff*tan(60); // xoff=3.22;

ha2=ha+yoff/sin(30);// s*sqrt(3.0)/2.0 + 3.72

p=[[0,0,0], //0

[s,0,0], //1

[c,ha,0], //2

[-xoff,-yoff,z], //3

[s+xoff,-yoff,z],//4

[c,ha2,z]]; //5

f=[ [0,1,2], [3,4,5], [0,1,4,3], [1,2,5,4], [0,2,5,3] ];

if (center)

translate ([-c, -ha/2, 0]) polyhedron( points=p , faces=f );

else

polyhedron( points=p , faces=f );

}

slant=10.55; // measured angle from 3way

//slant=0; //testing, for no slope

base=6;

tube=10;

height=base*cos(slant);

zoff=tube*tan(slant);

translate([0,0,zoff]) slantedprism(base, height, slant,true);

//why cant i add more stuff?

//translate([0,0,-zoff]) slantedprism(-base, -height, slant,true);

// or add some tubes (cylinder in cylinder)

/*

translate([0,0,7]) difference () {

cylinder(h=tube,r=base/2);

cylinder(h=tube,r=(base-2)/2); // leaving wall thickness as 2

}

*/

7 Comments
2024/03/20
21:12 UTC

2

Fill in points on a curve

I'm using one of these to copy a shape that is not an ellipse or a circle:

https://preview.redd.it/18t0ewa4odpc1.jpg?width=450&format=pjpg&auto=webp&s=2f362ea6c145feed312fb8f977620cb58b23de6d

I have put in the distances for the shape and I know the spacing of the shims. How do I add points win between to smooth out the result? My math is weak. 😀

9 Comments
2024/03/19
23:47 UTC

1

Resolution

I understand this community may not be interested in 3D printing, though I was curious how 3D printing software interprets measurements that are beyond it's resolution. For example:

I want to print a set of drawer trays where 98.6mm is not enough, and 98.65mm is too much. If 98.625 is not divisible by the nozzle diameter(0.04), how is this calculated, and should I be using only measurements which are divisible by the nozzle diameter?

9 Comments
2024/03/18
21:47 UTC

2

Evenly spacing holes of different diameters

Hi, trying to space out hole in smart way. Like this ...

difference() {

    cube(size = [150,70,7]);

    for (i =[8:14]){
     
     translate([i*4, 20 ,0]) 
     cylinder(8,i,i);   

 }     
}

It just dosent space out the way I would like ;-)

https://preview.redd.it/8bvus2xdj4pc1.png?width=487&format=png&auto=webp&s=b487ed1c0fed0127e3b3043494264d236cdeec74

6 Comments
2024/03/18
17:01 UTC

0

OpenSCAD cgal error (version 2024.03.17)

The rendering took a long time with version 2024.03.17, and failed with the below message.

(I couldn't copy it from the console).

What can I do to solve or avoid the problem?

https://preview.redd.it/b18uchsm11pc1.jpg?width=1599&format=pjpg&auto=webp&s=42e9071d0de33bf079b7216cc68358232c8a5768

7 Comments
2024/03/18
05:21 UTC

1

Universal 2D shape to 3D container script

Been playing with this script to create a container from any random 2D shape. You define the shape in the shape2d() module, then call it in the container() module. Any suggestions for enhancement would be welcome, but it works rather nicely!

 module shape2d() {
//    square(45);
circle(25);
//    text("G",font="Quicksand:style=Bold",size=200);
//    text("O",size=200);
//polygon(points=\[\[0,0\],\[100,0\],\[0,100\],\[10,10\],\[80,10\],\[10,80\]\], paths=\[\[0,1,2\],\[3,4,5\]\],convexity=10);
}

module container(height=25,wall=1){
linear\_extrude(wall)
shape2d();
linear\_extrude(height){
difference(){
offset(r=wall){
shape2d();
}
shape2d();
}
}
}

//scale(\[20,20\]) 
container();
4 Comments
2024/03/17
20:26 UTC

1

Decimals in Customizer

I was wondering how I could input decimal values in the customizer, as I can't seem to be able to do that. I'm only able to input integer values. Is this normal?

1 Comment
2024/03/17
17:52 UTC

1

Problem: Windows Installed Font Doesn't Appear in OpenSCAD

5 Comments
2024/03/17
10:11 UTC

1

Cylinder is allways created with 1,1,1 as parameters

Hello i have an Issue with the following code. the cylinder command ignores any parameters and always creates one with the dimensions of 1,1,1. Does anyone have any Idea whats the issue?

MM_bracket(80,5,10,3,71.5);
module MM_bracket(length_per_unit,depth, hight,unit_cnt,holedist_end){
    difference(){
        cube([depth,unit_cnt*length_per_unit+4,hight],center=true);
        if(unit_cnt%2==0){    
            for(x=[1:1:unit_cnt/2+1])
                if(x==unit_cnt/2+1){
                    translate([0,length_per_unit*(x-2)+holedist_end,0])
                    rotate([0,90,0])
                    cylinder([depth+2,1,1],center=true);
                    translate([0,-length_per_unit*(x-2)-holedist_end,0])
                    rotate([0,90,0])
                    cylinder([depth+2,1,1],center=true);
                    
                }
                else{
                    translate([0,length_per_unit*(x-1),0])
                    rotate([0,90,0])
                    cylinder([depth+2,1,1],center=true);
                    translate([0,-length_per_unit*(x-1),0])
                    rotate([0,90,0])
                    cylinder([depth+2,1,1],center=true);
                    
                }
        }
        else{    
            for(x=[1:1:unit_cnt])
                if(x==unit_cnt){
                    translate([0,length_per_unit*(x-2)+holedist_end/2,0])
                    rotate([0,90,0])
                    cylinder([depth+2,1,1],center=true);
                    translate([0,-length_per_unit*(x-2)-holedist_end/2,0])
                    rotate([0,90,0])
                    cylinder([depth+2,1,1],center=true);
                    
                }
                else{
                    translate([0,length_per_unit*(x-1.5),0])
                    rotate([0,90,0])
                    cylinder([depth+2,1,1],center=true);
                    translate([0,-length_per_unit*(x-1.5),0])
                    rotate([0,90,0])
                    cylinder([depth+2,1,1],center=true);
                    
                }
        }
    }
}

This part of the code should create walls with holes for mounting (should go where pink dots are in the screenshot)

A dual fan bracket with hand drawn dots indicating the position for screw holes

Version information (installed the package from the standard repository):
OpenSCAD Version: 2021.01
System information: Linux 6.7.7-1-MANJARO #1 SMP PREEMPT_DYNAMIC Fri Mar 1 18:26:06 UTC 2024 x86_64 Manjaro Linux 16 CPUs 31.06 GB RAM
User Agent: OpenSCAD/2021.01 (Linux x86_64; Manjaro Linux)
Compiler: GCC "13.2.1 20230801" 64bit

Has anyone any idea what the issue is?

7 Comments
2024/03/17
01:55 UTC

4

Beveling the edges of an irregular angled cut

I can solve this problem with minkowski() but I'd prefer not to.

Suppose I have a prism with some non-uniform polygon cross section, like a scalene triangle.

Now I want to take another arbitrary cross-section prism (say, a pentagon with unequal sides) and use it to subtract a big notch at an arbitrary angle from the first prism.

How would I bevel the edge of that cutout?

Example image and code:

Arbitrary cut to be beveled

difference() {
    linear_extrude(50) polygon(points=[[0,10], [-9,-4], [7,1]]);
    translate([-7,0,25]) rotate([-67,0,0])
        #linear_extrude(40, center=true)
            polygon(points=[[5,6], [-1,5], [-6,0], [-2,-5], [5,-5]]);
}

The way I'd do this with minkowski() is to make the first object a little smaller and the second object a little bigger, then do a minkowski sum of the final cut object with a small octahedron sized so that the original surfaces end up where I want. The bevels would be 45° rather than normal to the edges but it would be good enough.

The problem is, the thing I need to do this on isn't a simple shape like the example, it has compound curves with thousands of facets. That's why I want to avoid minkowski if I can. On the other hand, I'd also be OK with a solution that's slower than minkowski if the results were better.

0 Comments
2024/03/16
21:39 UTC

Back To Top