如何编辑此 SCAD 文件中的孔尺寸

Posted

技术标签:

【中文标题】如何编辑此 SCAD 文件中的孔尺寸【英文标题】:How to edit the hole size in this SCAD file 【发布时间】:2021-07-29 04:12:34 【问题描述】:

我对 3D 建模非常陌生(今天才开始),我发现 Iron Momo 的这个惊人的代码(链接:https://www.thingiverse.com/thing:211020)。我可以在 OpenSCAD 中编辑它 (https://openscad.org/downloads.html)

我唯一的问题是我需要每行的孔大小不同,一排 16 毫米,另一排 13 毫米。用下面的代码可以吗?

感谢您提前提供的任何帮助!

//Customizable test tube rack
//by Iron Momo

// preview[view:north, tilt:top]

/* [Basic] */

//Number of tubes
nb_tubes = 5; //[1:20]
//Number of rows
nb_rows = 1; //[1:10]

//Tubes diameter (mm)
hole_diameter = 16;

//Material thickness (mm)
thickness = 5; //[3,4,5,10]

//Total height (mm)
height1 = 80;
//Middle height (mm)
height2 = 20;


output_type = "STL"; //[DXF,STL]

/* [Hidden] */
inter=10;
width1 = nb_tubes*hole_diameter + (nb_tubes+1)*inter;
width2 = nb_tubes*hole_diameter + (nb_tubes+1)*inter+2*thickness;
depth1= nb_rows*hole_diameter+nb_rows*inter;
depth2= nb_rows*hole_diameter+nb_rows*inter+2*thickness;

if(output_type=="STL")
linear_extrude(height = thickness, center = false) rack_creation();


if(output_type=="DXF")
rack_creation();

module rack_creation()

bottom();
translate([0,depth2+5,0]) middle();
translate([0,2*depth2+10,0]) top();
translate([0,-height2-15,0])side1();
translate([0,-2*height2-30,0])side1();
translate([-5,-2*height2-30,0])rotate([0,0,90])side2();
translate([-5,height1-2*height2,0])rotate([0,0,90])side2();





module bottom()

difference()

    square([width2,depth2]);
    for (i = [1:nb_tubes])
        
            translate([thickness+i*inter+(i-1)*hole_diameter,0,0]) square([hole_diameter,thickness]);

            translate([thickness+i*inter+(i-1)*hole_diameter,depth1+thickness,0]) square([hole_diameter,thickness]);
        

    translate([0,depth2/5,0]) square([thickness,depth2/5]);
    translate([0,3*depth2/5,0]) square([thickness,depth2/5]);

    translate([width1+thickness,depth2/5,0]) square([thickness,depth2/5]);
    translate([width1+thickness,3*depth2/5,0]) square([thickness,depth2/5]);




module top()

difference()

    square([width2,depth2]);
    for (i=[0:nb_rows-1])
        
            for (j = [1:nb_tubes])
                
                    translate([thickness+j*inter+(j-1)*hole_diameter+hole_diameter/2,thickness+inter/2+hole_diameter/2+i*(hole_diameter+inter),0]) circle(hole_diameter/2);
                
        

    translate([0,depth2/5,0]) square([thickness,depth2/5]);
    translate([0,3*(depth2/5),0]) square([thickness,depth2/5]);

    translate([width1+thickness,depth2/5,0]) square([thickness,depth2/5]);
    translate([width1+thickness,3*(depth2/5),0]) square([thickness,depth2/5]);



module middle()

difference()

top();
for (i = [1:nb_tubes])
    
        translate([thickness+i*inter+(i-1)*hole_diameter,0,0]) square([hole_diameter,thickness]);

        translate([thickness+i*inter+(i-1)*hole_diameter,depth1+thickness,0]) square([hole_diameter,thickness]);
    




module side1()

difference()

    translate([0,thickness,0]) square([width2,height2]);

    translate([0,thickness+height2/3,0]) square([thickness,height2/3]);
    translate([width1+thickness,thickness+height2/3,0]) square([thickness,height2/3]);

for (i = [1:nb_tubes])
    
        translate([thickness+i*inter+(i-1)*hole_diameter,0,0]) square([hole_diameter,thickness]);

        translate([thickness+i*inter+(i-1)*hole_diameter,height2+thickness,0]) square([hole_diameter,thickness]);
    


module side2()

difference() 

    //Forme de base
    translate([thickness,0,0]) square([height1,depth2]);

    //Trous middle
    translate([height2+thickness,0,0]) square([thickness,depth2/5]);
    translate([height2+thickness,4*depth2/5,0]) square([thickness,depth2/5]);
    translate([height2+thickness,2*depth2/5,0]) square([thickness,depth2/5]);

    //Trous side1
    translate([thickness,0,0]) square([height2/3,thickness]);
    translate([thickness,depth1+thickness,0]) square([height2/3,thickness]);
    translate([thickness+2*height2/3,0,0]) square([height2/3,thickness]);
    translate([thickness+2*height2/3,depth1+thickness,0]) square([height2/3,thickness]);




//Ajout bottom
translate([0,depth2/5,0]) square([thickness,depth2/5]);
translate([0,3*(depth2/5),0]) square([thickness,depth2/5]);


//Ajout top
translate([height1+thickness,depth2/5,0]) square([thickness,depth2/5]);
translate([height1+thickness,3*(depth2/5),0]) square([thickness,depth2/5]);




【问题讨论】:

【参考方案1】:

带有孔的元素是由同一个模块创建的,模块top()。在示例中,孔的大小在模块中设置

circle(hole_diameter/2);

所以 top() 的每个实例都具有相同的孔直径。要解决这个问题,您可以使用参数调用模块,请参阅https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/User-Defined_Functions_and_Modules#Modules

module top(hd)

difference()

    square([width2,depth2]);
    for (i=[0:nb_rows-1])
        
            for (j = [1:nb_tubes])
                
                translate([thickness+j*inter+(j-1)*hole_diameter+hole_diameter/2,thickness+inter/2+hole_diameter/2+i*(hole_diameter+inter),0]) circle(hd/2);
                
        

    translate([0,depth2/5,0]) square([thickness,depth2/5]);
    translate([0,3*(depth2/5),0]) square([thickness,depth2/5]);

    translate([width1+thickness,depth2/5,0]) square([thickness,depth2/5]);
    translate([width1+thickness,3*(depth2/5),0]) square([thickness,depth2/5]);



module middle(hd)

difference()

top(hd);
for (i = [1:nb_tubes])
    
        translate([thickness+i*inter+(i-1)*hole_diameter,0,0]) square([hole_diameter,thickness]);

        translate([thickness+i*inter+(i-1)*hole_diameter,depth1+thickness,0])       square([hole_diameter,thickness]);
    


然后设置另一个变量:

//Tubes diameter (mm)
hole_diameter = 16;    // of the middle element
hole_diameter_1 = 13;  // of the top element

并在 rack_creation() 中调用模块 top() 和 middle() 时使用它们:

module rack_creation()

bottom();
translate([0,depth2+5,0]) middle(hole_diameter);
translate([0,2*depth2+10,0]) top(hole_diameter_1);
…

【讨论】:

以上是关于如何编辑此 SCAD 文件中的孔尺寸的主要内容,如果未能解决你的问题,请参考以下文章

如何填充使用 geopandas 溶解地理数据框时创建的多面体中的孔?

solidworks装配体中如何编辑阵列后的单个零件

powershell PowerShell文件,用于根据图像尺寸递归重命名和编辑目录中的图像。

引导清除修复不起作用。布局镀铬中的孔

PDF图片怎么修改?如何修改PDF文件中的图片大小!

python 检查缺失值的百分比和df列中的孔的趋势以及它们是否连续。