A free, open source, programming language for describing physical objects. "Code Reality"
OpenSCAD is an open source CAD system that uses a programming language to describe physical objects. Although not as intuitive as other CAD programs, this does enable code reuse, combining, and libraries as well as parametric "variables" which greatly increase it's power when making complex objects.
Instead of drawing /an/ object, in OpenSCAD, you describe the idea of the object and then OpenSCAD draws any number of that sort of object for you. It can also animate or even simulate the operation of the object.
Objects are:
cube(size ); //All units are millimeters cube([x,y,z]); //1:1:1mm if size not specified //actually a rectangular prism if x, y, & z are not equal sphere(r=radius); // the "r=" is optional. 1mm if no radius cylinder(r=radius, h=height); //r=1 & h=1 if not provided cylinder(r1=top, r2=bottom, h=height); //makes a cone if r1=0 //add ",center=true" to any object to place it at the origin.
rotate([x,y,z]) { object } //rotates the object the specified degrees (+/-) //along the specified axis translate([x,y,z]) { object } //moves the object from it's origin scale(factor) { object } //scales the object by the factor (can be a fraction) scale([x,y,z]) { object } //scales the object along the specified axis
difference() { object object_list } // the later objects are subtracted from the first union() { object_list } // all parts of all objects are combined intersection() { object_list } // only the overlapping parts of all objects
Placing a "%" before the primitive causes it to be shown as partly transparent and removed from the actual object.
%cube([x,y,z]);
This can be used to "see through" a complex part or to add a "reference" object which is not considered part of the final product, but simply shown to help coordinate the drawing.
All curves in OpenSCAD are approximated by straight segments. These specify the accuracy of approximations in 1 of 3 different ways:
$fa=angle; // degrees between each segment. $fs=length; // length of each segment $fn=number; // number of segments // Also useful to make regular polygons. e.g. cylinder(r=10,h=15,$fn=6); // makes a hexagon
One of the biggest advantages of OpenSCAD is that it can make "parametric objects" which adjust in complex ways.
These parameters look like variables in a program, but they aren't really. You can not re-assign the value*.
I=0; translate([I*10,0,0]) cube(5); I=I+1; // this causes an error. Instead, use: for ( I = [0 : 5] ) { translate([I*10,0,0]) cube(5); }
The for statements allows an object to be called many times with a range or list of parameters.
for ( parameter = [start : end] ) { object(parameter) } for ( parameter = [start : step : end] ) { object(parameter) } for ( parameter = [option[, options] ] ) { object(parameter) } //Example to make a nut head of Size, Height. for (r = [-60, 0, 60]) rotate([0,0,r]) cube([Size*1.75, Size, Height], true); }
Different options can be selected using
if(condition) { objects } if(condition) { objects } else { objects }
Note that == is comparison, NOT =
Complex objects can be grouped into modules and re-used with different parameters, very much like a subroutine:
module name(parameter[=default] [,parameters]) {objects}
Multiple parameters can be listed, and each can optionally have a default value, allowing the user to not pass it when using the module. To use the module:
name(); // invoke the module with default parameters name(parameter=value); // override the default with a value
The real power of OpenSCAD comes from reusing code already written.
#include <complexObject.scad> module name(ValueParameter=5, OptionParameter=34);
code libraries are available for many amazingly complex objects such as pulleys, gears, clocks, servo or motor mounts, etc...
OpenSCAD can produce several types of files from the Design menu. You must Compile and Render the design (F6) before it can be exported.
Click View / Animate and enter FPS (Frames per Second) and Steps. E.g. 10 FPS, 100 Steps. The design will be repeatedly re-rendered, and the value in the Time field will appear in the script in the special variable $t. If "Dump " is enabled, a new PNG file for each rendering will be saved in the same folder as the .scad file being edited. This simple program:
rotate([0,0,$t*360]) cube(); //spin a cube thru 360 degrees
will produce frames of a cube spinning. Use a program like the convert module in ImageMagick to make those frames into a video.
convert 'frame*.png' -set delay 1x24 animated.gif
By transforming parts of an object, you can make complex animations:
See also:
file: /Techref/app/openscad.htm, 8KB, , updated: 2018/11/9 17:25, local time: 2024/8/14 20:16,
3.128.226.125:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://piclist.com/Techref/app/openscad.htm"> OpenSCAD: CAD Application </A> |
Did you find what you needed? |
![]() o List host: MIT, Site host massmind.org, Top posters @none found - Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
Welcome to piclist.com! |
.