UsingOpenSCAD

From Clothbot

(Difference between revisions)
Jump to: navigation, search
Revision as of 20:37, 7 November 2009 (edit)
AndrewPlumb (Talk | contribs)

← Previous diff
Revision as of 20:42, 7 November 2009 (edit)
AndrewPlumb (Talk | contribs)

Next diff →
Line 15: Line 15:
Variables are defined using '''<name>''' '''=''' '''<value>''' ''';''' syntax. Variables are defined using '''<name>''' '''=''' '''<value>''' ''';''' syntax.
- my_variable = 10;+ overlap = 10;
== Module Declarations == == Module Declarations ==
-A module with no arguments:+Modules with no arguments:
module peg() module peg()
Line 28: Line 28:
} }
} }
 + module thread_hole()
 + {
 + translate([0,0,-overlap]) cylinder(h=180+320+2*overlap, r=100, center=false);
 + }
 +
 +
 +A module with one argument:
 +
 + module peg_hole(shift_bottom=200)
 + {
 + translate([0,0,-overlap]) union() {
 + cylinder(h=180+320+2*overlap, r=150, center=false);
 + translate([0,0,overlap-1+shift_bottom])
 + cylinder(h=250+1, r1=250+1, r2=0, center=false);
 + cylinder(h=overlap+shift_bottom, r=250, center=false);
 + }
 + }
 +
 +Module declarations can contain sub-module declarations:
 +
 + module disc_button()
 + {
 + module bottom_disc_threadholes(shift_middle=5)
 + {
 + union() {
 + translate([0,0,200+shift_middle]) cylinder(h=130+shift_middle,r=500,center=false);
 + translate([400,0,0]) thread_hole();
 + translate([-400,0,0]) thread_hole();
 + translate([0,400,0]) thread_hole();
 + translate([0,-400,0]) thread_hole();
 + }
 + }
 + module bottom_disc()
 + {
 + difference() {
 + cylinder(h=320, r=800, center=false);
 + bottom_disc_threadholes(shift_middle=0);
 + }
 + translate([400, 400, 0])
 + peg();
 + translate([400, -400, 0])
 + peg();
 + translate([-400, -400, 0])
 + peg();
 + translate([-400, 400, 0])
 + peg();
 + }
 + module bottom_disc_holes()
 + {
 + translate([400, 400, 0])
 + peg_hole(shift_bottom=180+overlap);
 + translate([400, -400, 0])
 + peg_hole(shift_bottom=180+overlap);
 + translate([-400, -400, 0])
 + peg_hole(shift_bottom=180+overlap);
 + translate([-400, 400, 0])
 + peg_hole(shift_bottom=180+overlap);
 + }
 + difference() {
 + bottom_disc();
 + bottom_disc_holes();
 + }
 + }
 +
 +Modules are called/instantiated:
 +
 + disc_button();

Revision as of 20:42, 7 November 2009

Contents

Using OpenSCAD

This page is to hold my notes on using OpenSCAD.

Syntax

Comments

Comments are escaped with the // character prefix.

// This is a comment

Variable Declarations

Variables are defined using <name> = <value> ; syntax.

overlap = 10;

Module Declarations

Modules with no arguments:

module peg()
{
	union() {
		translate([0,0,320-overlap]) cylinder(h=180+overlap, r=245, center=false);
		cylinder(h=320, r=245+55, center=false);
	}
}
module thread_hole()
{
	translate([0,0,-overlap]) cylinder(h=180+320+2*overlap, r=100, center=false);
}


A module with one argument:

module peg_hole(shift_bottom=200)
{
	translate([0,0,-overlap]) union() {
		cylinder(h=180+320+2*overlap, r=150, center=false);
		translate([0,0,overlap-1+shift_bottom])
			cylinder(h=250+1, r1=250+1, r2=0, center=false);
		cylinder(h=overlap+shift_bottom, r=250, center=false);
	}
}

Module declarations can contain sub-module declarations:

module disc_button()
{
	module bottom_disc_threadholes(shift_middle=5)
	{
		union() {
		translate([0,0,200+shift_middle]) cylinder(h=130+shift_middle,r=500,center=false);
		translate([400,0,0]) thread_hole();
		translate([-400,0,0]) thread_hole();
		translate([0,400,0]) thread_hole();
		translate([0,-400,0]) thread_hole();
		}
	}
	module bottom_disc()
	{
		difference() {
			cylinder(h=320, r=800, center=false);
			bottom_disc_threadholes(shift_middle=0);
		}
		translate([400, 400, 0])
			peg();
		translate([400, -400, 0])
			peg();
		translate([-400, -400, 0])
			peg();
		translate([-400, 400, 0])
			peg();
	}
	module bottom_disc_holes()
	{
		translate([400, 400, 0])
			peg_hole(shift_bottom=180+overlap);
		translate([400, -400, 0])
			peg_hole(shift_bottom=180+overlap);
		translate([-400, -400, 0])
			peg_hole(shift_bottom=180+overlap);
		translate([-400, 400, 0])
			peg_hole(shift_bottom=180+overlap);
	}
	difference() {
		bottom_disc();
		bottom_disc_holes();
	}
}

Modules are called/instantiated:

disc_button();
Personal tools