OpenSCAD User Manual/The OpenSCAD Language
General

OpenSCAD では C++形式のコメントを用いる:
General

変数は以下のように簡単に作ることができる。
General

例:
General

ダブルクォートとバックスラッシュはエスケープする必要がある (順に\" と \\ )。その他のエスケープ文字は、改行 (\n)、タブ (\t) とCR (\r) である。
General

NB! この仕様は OpenSCAD-2011.04 からである。古いソースはsed コマンド『sed 's/\\/\\\\/' non-escaped.scad > escaped.scad』で変換できる。
General

例:
General

Output: ECHO: "The quick brown fox jumps "over" the lazy dog. The quick brown fox. The \lazy\ dog."
General

注意: OpenSCAD は変数の値の計算を実行時ではなくコンパイル時に行なうので、 一番最後に代入された値がプログラム中のあらゆる参照で有効となる。 変数というより、再定義可能な定数と考えたほうがよいかもしれない。
General

例:
General

出力
General

このことから、変数は "if" ブロックの中では代入できない:
General

Example:
General

出力 Compile Error
General

この振る舞いのスコープは、root (一番上のレベル) または module の呼び出しごとに限られる。 このことから、変数はスコープの外部に影響されることなくモジュール内で再定義できる。 しかしスコープ内でのすべてのインスタンスは、上述のように最後に定義された値になる。
General

例:
General

Output
General

これは直感に反するようであるが、面白い使い方ができる。 つまり、デフォルト値を持つようなシェアードライブラリを作成した場合、そのファイルをインクルードしたファイルでは、 単純にデフォルト値を『再定義』つまり上書きするだけで新しい値で使うことができる。
General

変数の値のスコープをより厳密に定義するには、assign ステートメントを参照。
General

Now we have variables, it would be nice to be able to get input into them instead of setting the values from code. There are a few functions to read data from DXF files, or you can set a variable with the -D switch on the command line.
General

Getting a point from a drawing
General

Getting a point is useful for reading an origin point in a 2D view in a technical drawing. The function dxf_cross will read the intersection of two lines on a layer you specify and return the intersection point. This means that the point must be given with two lines in the DXF file, and not a point entity.
General

Getting a dimension value
General

You can read dimensions from a technical drawing. This can be useful to read a rotation angle, an extrusion height, or spacing between parts. In the drawing, create a dimension that does not show the dimension value, but an identifier. To read the value, you specify this identifier from your script:
General

For a nice example of both functions, see Example009 and the image on the homepage of OpenSCAD.
General

配列要素の値または範囲に基づいて繰り返し実行する。
General

配列要素の値: for (変数=<配列>) <実行されるもの> - <変数> には配列の値が次々に代入される 範囲: for (変数=<範囲>) <実行されるもの>
General

範囲: [<初期値>:<終値>] - 初期値から終値まで繰り返す。<終値> は <初期値> より小さくてもよい。 範囲: [<初期値>:<増分>:<終値>] - 初期値から終値まで増分だけ増やして繰り返す。増分は非整数でもよい。 注意: 増分は正の絶対値である必要がある。もし <終値> が <初期値> より小さくとも、増分は絶対値でなくてはならない。 警告: 増分で (<end>-<start>) が割り切れない場合、繰り返しの実際の終値は <end>-(<end>-<start> mod <increment>) となる (訳注: 範囲を超えることはない。初期値1、終値6、差分2の場合、1、3、5が代入される)。
General

ループのネスト : for (変数1 = <範囲または配列>, 変数2 = <範囲または配列> ) <両方の変数を変化させて実行されるもの> for ループは通常のプログラム同様、ネストできる。ひとつのfor文で両方の繰り返しを実行できる。
General

Nested loop example
General

配列または範囲による繰り返しを実行し、描いたものの交わり (intersection) をとる。
General

注: intersection_for() は、通常のfor() 文と intersection() 文を用いた結果と同じにならない問題があり、対処中である。
General

パラメータ
General

サブツリー内を条件によって評価する。
General

引数
General

例:
General

変数にサブツリー内での新しい値を代入する。
General

引数
General

例:
General

Update:
General

このバージョンから値の代入は好きなところでできるため、assign() は必要ない (assign() は後方互換性のために残されている)。
General

OpenSCAD User Manual/Mathematical Operators
General

OpenSCAD User Manual/Mathematical Functions
General

OpenSCAD User Manual/String Functions
General

原点の座標に直方体を作る。 centerがtrueの際、原点を中心に作られ、falseの際はx, y, z 共に正の方向に作られる。 引数が下記のパラメータと同じ順ならば、引数の名前を省略し、値だけを入力してもよい。
General

引数
General

例:
General

原点を中心に球を作る。引数名は省略可である。
General

引数
General

例:
General

座標系の原点に円筒を生成する。 1つの半径 (r) を指定すると円筒になり、2つの異なる半径 (r1, r2) を指定すると円錐になる。
General

引数
General

デフォルトは false、つまり円筒の底面 (半径 r1) が原点となる。
General

例:
General

Create a polyhedron with a list of points and a list of triangles. The point list is all the vertexes of the shape, the triangle list is how the points relates to the surfaces of the polyhedron.
General

Parameters
General

Syntax example
General

Triangle points ordering When looking at the face from the outside inwards, the points must be clockwise. You can rearrange the order of the points or the order they are referenced in each triangle triple. The order of triangles is immaterial. Note that if your polygons are not all oriented the same way OpenSCAD will either print an error or crash completely, so pay attention to the vertex ordering.
General

Example, a square base pyramid:
General

Ordering of triangle points An example of a more complex polyhedron, and showing how to fix polyhedrons with badly oriented polygons.
General

When you select 'Thrown together' from the view menu and compile the design (not compile and render!) you will see a preview with the mis-oriented polygons highlighted. Unfortunately this highlighting is not possible in the OpenCSG preview mode because it would interfere with the way the OpenCSG preview mode is implemented.)
General

Below you can see the code and the picture of such a problematic polyhedron, the bad polygons (triangles or compositions of triangles) are in pink.
General

A correct polyhedron would be the following:
General

Beginner's tip:
General

If you don't really understand "orientation", try to identify the mis-oriented pink triangles and then permute the references to the points vectors until you get it right. E.g. in the above example, the third triangle ([0,4,5]) was wrong and we fixed it as [4,0,5]. In addition, you may select "Show Edges" from the "View Menu", print a screen capture and number both the points and the triangles. In our example, the points are annotated in black and the triangles in blue. Turn the object around and make a second copy from the back if needed. This way you can keep track.
General

Clockwise Technique:
General

Orientation is determined by clockwise indexing. This means that if you're looking at the triangle (in this case [4,0,5]) from the outside you'll see that the path is clockwise around the center of the face. The winding order [4,0,5] is clockwise and therefore good. The winding order [0,4,5] is counter-clockwise and therefore bad. Likewise, any other clockwise order of [4,0,5] works: [5,4,0] & [0,5,4] are good too. If you use the clockwise technique, you'll always have your faces outside (outside of OpenSCAD, other programs do use counter-clockwise as the outside though).
General

Think of it as a Left Hand Rule:
General

If you hold the triangle and the fingers of your hand curls is the same order as the points, then your thumb points outwards.
General

Succinct description of a 'Polyhedron'
General

Each point, in the point list, is defined with a 3-tuple x,y,z position specification. Points in the point list are automatically given an identifier starting at zero for use in the triangle list (0,1,2,3,... etc).
General

Each triangle, in the triangle list, is defined by selecting 3 of the points (using the point identifier) out of the point list.
General

e.g. triangles=[ [0,1,2] ] defines a triangle from the first point (points are zero referenced) to the second point and then to the third point.
General

When looking at any triangle from the outside, the triangle must list their 3 points in a clockwise order.
General

OpenSCAD User Manual/Transformations
General

子ノードの和集合を作る。
General

2番目以降の子ノードを減算する。
General

すべての子ノードの共通部分を残す。
General

常に (even in OpenCSG プレビューモードでも) 子ノードのブーリアンモデルを計算する。
General

例:
General

この例は、convexity が4である2次元の図形を示している。赤線で示した光線は、図形と4回交差している。 3次元の場合も同様である。大抵の立体では、10程度にしておけばよい。
General

OpenSCAD User Manual/Modifier Characters
General

モジュール(他の言語でのマクロ、関数にあたる)は処理の再利用を容易にする。
General

この例では、引数 distance、rot、size を設定して呼び出すことにより、このような描画を複数繰り返す場合のプログラムの行数を節約し、 プログラムの可動性を上げる。
General

呼び出しは、次の例のようにC言語の関数呼び出しに似た方法で、値または数式を渡して行なう。
General

The child nodes of the module instantiation can be accessed using the children() statement within the module. The number of module children can be accessed using the $children variable.
General

Parameters
General

Deprecated child() module
General

Up to release 2013.06 the now deprecated child() module was used instead. This can be translated to the new children() according to the table:
General

Examples
General

Transfer all children to another module:
General

Use the first child, multiple time:
General

If you need to make your module iterate over all children you will need to make use of the $children variable, e.g.:
General

One can specify default values for the arguments:
General

And then use one of the following ways to supply the arguments
General

OpenSCAD User Manual/STL Import
General

OpenSCAD User Manual/Include Statement
General

All variables starting with a '$' are special variables. The semantic is similar to the special variables in lisp: they have dynamic instead of lexical scoping.
General

The $fa, $fs and $fn special variables control the number of facets used to generate an arc:
General

$fa is the minimum angle for a fragment. Even a huge circle does not have more fragments than 360 divided by this number. The default value is 12 (i.e. 30 fragments for a full circle). The minimum allowed value is 0.01. Any attempt to set a lower value will cause a warning.
General

$fs is the minimum size of a fragment. Because of this variable very small circles have a smaller number of fragments than specified using $fa. The default value is 2. The minimum allowed value is 0.01. Any attempt to set a lower value will cause a warning.
General

$fn is usually 0. When this variable has a value greater than zero, the other two variables are ignored and full circle is rendered using this number of fragments. The default value is 0.
General

When $fa and $fs are used to determine the number of fragments for a circle, then OpenSCAD will never use less than 5 fragments.
General

This is the C code that calculates the number of fragments in a circle:
General

Spheres are first sliced into as many slices as the number of fragments being used to render a circle of the sphere's radius, and then every slice is rendered into as many fragments as are needed for the slice radius. You might have recognized already that the pole of a sphere is usually a pentagon. This is why.
General

The number of fragments for a cylinder is determined using the greater of the two radii.
General

The method is also used when rendering circles and arcs from DXF files.
General

You can generate high resolution spheres by resetting the $fX values in the instantiating module:
General

or simply by passing the special variable as parameter:
General

You can even scale the special variable instead of resetting it:
General

The $t variable is used for animation. If you enable the animation frame with view->animate and give a value for "FPS" and "Steps", the "Time" field shows the current value of $t. With this information in mind, you can animate your design. The design is recompiled every 1/"FPS" seconds with $t incremented by 1/"Steps" for "Steps" times, ending at either $t=1 or $t=1-1/steps.
General

If "Dump Pictures" is checked, then images will be created in the same directory as the .scad file, using the following $t values, and saved in the following files:
General

Or, for other values of Steps, it follows this pattern:
General

Which pattern it chooses appears to be an unpredictable, but consistent, function of Steps. For example, when Steps=4, it follows the first pattern, and outputs a total of 4 files. When Steps=3, it follows the second pattern, and also outputs 4 files. It will always output either Steps or Steps+1 files, though it may not be predictable which. When finished, it will wrap around and recreate each of the files, looping through and recreating them forever.
General

These contain the current viewport rotation and translation - at the time of doing the rendering. Moving he viewport does not update them. During an animation they are updated for each frame.
General

It's not possible to write to them and thus change the viewport parameters (although that could be a decent enough idea).
General

Example
General

which makes the cube change size based on the view angle, if an animation loop is active (which does not need to use the $t variable)
General

You can also make bits of a complex model vanish as you change the view.
General

The menu command Edit - Paste Viewport Rotation/Translation copies the current value of the viewport, but not the current $vpd or $vpt.
General

Define a function for code readability and re-use.
General

Usage examples:
General

This function prints the contents to the compilation window (aka Console). Useful for debugging code.
General

The OpenSCAD console supports a subset of HTML markup language. See here for details.
General

Usage examples:
General

Shows in the Console as
General

Forces the generation of a mesh even in preview mode. Useful when the boolean operations become too slow to track.
General

Needs description.
General

Usage examples:
General

Example 1:
General

Result:
General

Example 2
General

Usage Pattern:
General

The following are some usage examples.
General

Example 5:
General

Returns:
General

Example 6: Return all matches per search vector element.
General

Returns:
General

Example 7: Return first match per search vector element; special case return vector.
General

Returns:
General

Example 8: Return first two matches per search vector element; vector of vectors.
General

Returns:
General

Example 9:
General

Returns