Creating an array of circles programmatically

The task of creating an array of holes was recently asked after:

The rather prosaic solution of drawing a column of circles, duping it, rotating the duplicate as needed, and then duping the column and aligning each duplicate as desired was met w/ the observation that it was more steps than were expected:

Here is a way to do this programmatically using freely available tools.

Start by registering for an account at:

https://www.blockscad3d.com/

(not strictly necessary, but it will allow saving projects to their servers while working — alternately, one can export XML and reload it)

Then download and install:

Go to:

https://www.blockscad3d.com/editor/

and begin a new project.

Save the new project with a suitable name and create the necessary variables:

  • Border Width — the space around the rectangular array
  • Hole Diameter — the diameter of the holes
  • Hoel Spacing — how closely or widely spaced they are
  • Columns — the number of columns along X
  • Rows — the number of rows along Y
  • Units — this will allow switching between Imperial and metric and scaling as desired

Rather than constantly multiply by Units, it is expedient to use new variables (w/ shorter names) which are pre-multiplied:

Create a rectangle (and add a forgotten variable, Stock Thickness for Z) and work up the appropriate formulas for sizing it:

A post was merged into an existing topic: How to create uniform hole patterns

Since it will be necessary to position and size things by the radius, it is expedient to add a variable for that:

and it will desirable to subtract the holes from the stock:

To ensure that the holes are cut cleanly they need to be repositioned down as well as over and up by the Border Width and Hole Radius:

2 Likes

Whilst this tutorial is being built for BlocksCAD, I put together a couple of scripts to do it using the BlocksCAD prerequisite OpenSCAD, which is quite wonderful in and of itself.

To draw circles and save them as SVG’s:

// Draw a grid of circles
//
// - All values are in mm
// - Adjust the variables, then hit F6 and export as an SVG

// variables
borderWidth = 30;
holeDiameter = 15;
holeSpacing = 20;
columns = 12;
rows = 6;


// other stuff :)
for (row=[0:rows-1],column = [0:columns-1]) {
   hole(row,column);
}

module hole(row, column) {
    x = column * (holeDiameter + holeSpacing);
    y = row * (holeDiameter + holeSpacing);
    translate([x + borderWidth,y + borderWidth,0]) {
        circle(d=holeDiameter);
    }
}

To draw holes in a block and save it as an STL or similar:

// Draw a grid of circles in a bit of stock
//
// - All values are in mm
// - Adjust the variables, then hit F6 and export as an STL or similar

// variables
stockThickness = 25;
borderWidth = 30;
holeDiameter = 15;
holeSpacing = 20;
columns = 12;
rows = 6;

// other stuff :)
difference(){
   stock();

   for (row=[0:rows-1],column = [0:columns-1]) {
      hole(row,column);
   }
}

module stock() {
    cube([
        (borderWidth*2) + ((columns-1)*(holeSpacing+holeDiameter)),
        (borderWidth*2) + ((rows-1)*(holeSpacing+holeDiameter)),
        ,stockThickness
    ]);
}

module hole(row, column) {
    x = column * (holeDiameter + holeSpacing);
    y = row * (holeDiameter + holeSpacing);
    translate([x + borderWidth,y + borderWidth,-1]) {
        cylinder(stockThickness+2,d=holeDiameter,center=false);
    }
}

2 Likes

There is a feature in CC under transform called Allign Vectors. Position the first row of holes where you want them. Then select all in each row and use Allign Vectors to line them up with the first row. Play with it and you will see what it does

@Gerry — no fair skipping forward — we’ll get to OpenSCAD, but won’t use an STL to get out of it, since that’s rather limiting in terms of CAM tool choices.

@baricl — unfortunately, CC’s current alignment options only allow aligning at extrema, and doesn’t have an option for doing two axes at once, so one would have to align twice for each instance — dragging into alignment is instead a single operation and fewer clicks.

So sorry… I saw what you were doing and thought I’d slap something together quickly. Feel free to delete it at post it later in context, if you like!

Adjust the numbers and formula a bit and add two loops:

Available at:

https://www.blockscad3d.com/community/projects/1123710

Save out the OpenSCAD file and open it in OpenSCAD:

and edit the OpenSCAD to rearrange the code as necessary:

so that one has the Customizer interface and can render to get a file which can be exported to DXF or SVG:

Array of circles-rectangular.dxf (261.1 KB)

Array of circles-rectangular.zip (4.4 KB)

Array of circles-rectangular

Array of circles-rectangular.c2d (1.4 MB)

Isn’t it easier to just change the CC background grid spacing. Eg along y to suit the desired width then change it to suit x if different.

Just my 2 cents worth.

1 Like

As I noted in the initial response:

EDIT: Note that since this post, Carbide Create has gained a Linear Array feature which allows doing this interactively in the program.

1 Like