OpenSCAD用戶手冊/FAQ

維基教科書,自由的教學讀本
跳至導覽 跳至搜尋

一般問題[編輯]

OpenSCAD怎麼念?[編輯]

OpenSCAD的發音為Open - ESS - CAD

顯示問題[編輯]

預覽功能似乎完全不起作用[編輯]

Force Goldfeather

在一些系統中,特別是跑在Intel GPUs上的Windows系統,往往會存在一些老舊或易崩潰的OpenGL驅動。這會影響差集或交集操作的有關預覽渲染。

下列步驟常用於改善這種問題:Edit->Preferences->Advanced->Force Goldfeather (參見截圖)。

預覽版中那些奇怪的閃爍失真是怎麼回事?[編輯]

OpenSCAD中重合面的顯示問題

這通常是由於不同對象共用一個或多個面所導致的,例如:

difference() {
  cube(20, center = true);
  cylinder(r = 10, h = 20, center = true);
}

在大多數情況下,最終渲染出的結果是完好的,but it's recommended to make the cuts a little bit larger to prevent this type of issues.

Note that this issue may also occur with faces that are not even visible in the final result, for example because they're removed by a difference() operation. This is an artifact of the library used for drawing the preview. See this discussion for an example and a workaround.

參見:https://en.wikipedia.org/wiki/Z-fighting


為什麼模型中的一些部分(如孔洞)無法正確地渲染出來?[編輯]

OpenSCAD display issue with convexity setting too low

This can happen when using features like linear_extrude() or when importing objects. The convexity of the objects is not known. For more complex objects, the convexity parameter can be used to specify the value. Note that higher values will cause a slowdown in preview.

difference() {
    linear_extrude(height = 15 /* , convexity = 2 */) {
        difference() {
            square([50, 50]);
            translate([10, 10]) circle(5);
        }
    }
    translate([25, 25]) cube([5, 5, 40], center = true);
}

See also https://en.wikipedia.org/wiki/Convexity_%28mathematics%29

為什麼用F5可以顯示出我的模型而F6卻不行?[編輯]

OpenSCAD polyhedron with flipped face

This can be caused by polyhedrons with flipped faces.

This can be visualized in "Thrown Together" display mode. See misordered faces for details.

points = [[5,5,0],[5,-5,0],[-5,-5,0],[-5,5,0],[0,0,3]];
faces = [[0,1,4],[1,2,4],[2,3,4],[3,4,0],[1,0,3],[2,1,3]];
polyhedron(points, faces);

If the model imports external STL files, see also import related question.


為神馬預覽速度那麼慢?[編輯]

http://forum.openscad.org/Why-is-for-so-slow-tp11511p11531.html

This is hard to explain, but in essence, having intersections as the negative objects in difference is expensive. The preview rendering algorithm only allows having primitive objects as negatives, and everything else has to be unpacked.

For example (using A+B = union() / A-B = difference() / A*B = intersection()):

A - B*C - D*E

becomes: A-B-D + A-B-E + A-C-D + A-C-E

..and if A is more complex:

A+B - C*D - E*F

becomes: A-C-E + A-C-F + A-D-E + A-D-F + B-C-E + B-C-F + B-D-E + B-D-F

All combinations have to be rendered, which can take some time, especially on older GPUs, and especially on low-end Intel GPUs.

導入數據問題[編輯]

為什麼用F5可以顯示我導入的STL文件,而F6卻不行?[編輯]

This is mostly caused by bad STL files, the best bet is to verify the STL file in a tool like Blender, MeshLab or NetFabb and fix the issues. In essence the model needs to be manifold to be processed in OpenSCAD.

The reason for the model still showing up in preview mode is that there is no real geometry calculation going on yet. The preview simply draws the triangles from the STL.

There is one specific issue that causes problems called "Zero faces" (meaning the STL contains triangles with zero area because all 3 points are on one line) which are currently not handled well in OpenSCAD.

Using MeshLab

MeshLab has a filter to remove zero faces by flipping edges of polygons

Filters -> Cleaning and Repairing -> Remove T-Vertices by Edge-Flip.

Set the Ratio to a very high value (e.g. 1000000), otherwise it's possible the model gets distorted.

Using Blender

Blender has a 3D-Printing-Toolbox Plug-in (needs to be enabled in the UserSettings) which can show issues with the STL file. See http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Modeling/PrintToolbox

Using NetFabb/Microsoft cloud service

The Microsoft 3D Model Repair service can help with fixing STL files. Make sure to read the service conditions before posting files. See https://modelrepair.azurewebsites.net/

在導入DXF文件時,我收到了"Unsupported DXF Entity"警告,這是什麼意思?[編輯]

DXF import sometimes produces warning messages like Unsupported DXF Entity 'SPLINE' (1c1) in "file.dxf". This means the DXF file is using features that the OpenSCAD importer does not know how to handle. The importer will simply ignore those unknown entities which could result in an incomplete model.

When using Inkscape, the easiest way to produces DXF files without unsupported entities is to convert all Bezier curves to short line segments using

Extensions -> Modify Path -> Flatten Beziers

The value given in the dialog will determine the length of the line segments. Lower values will produce smoother results, but also much more line segments. As export file format, use "Desktop Cutting Plotter (AutoCAD DXF R14)".

A more detailed tutorial is available at http://repraprip.blogspot.de/2011/05/inkscape-to-openscad-dxf-tutorial.html

導出數據問題[編輯]

我要怎樣做才能從一個腳本中導出多個零件呢?[編輯]

Answer based on comments in related issue on github https://github.com/openscad/openscad/pull/1534#issuecomment-227024209

There is a way to generate a bunch of geometric primitives and export them as STL files from a single script, without commenting/uncommenting code.

There is a variable, PARTNO, that indicates which part is being exported in the current run. If PARTNO is 'undef', then nothing is exported.

Image exported with PARTNO=0
 PARTNO = undef; // default part number
 
 module tree() {
   color("green") cylinder(r1 = 12, r2 = 1, h = 30);
   // ...
 }
 
 module trunk() {
   color("brown") cylinder(r = 3, h = 10);
   // ...
 }
 
 module base() {
   color("white") translate([-10, -10, 0]) cube([20, 20, 5]);
   // ...
 }
 
 if (PARTNO == 1) tree();
 if (PARTNO == 2) trunk();
 if (PARTNO == 3) base();
 
 // optionally use 0 for whole object
 if (PARTNO == 0) {
   base();
   translate([0, 0, 5]) trunk();
   translate([0, 0, 15]) tree();
 }

When working interactively, the PARTNO variable at the top of the file can be set to the number of the part that will be shown/exported from the GUI.

It's possible to automate the process of exporting all of the parts by writing a shell script on MacOS or Linux, or a batch file on Windows. The shell script would look something like this:

 # export parts as STL
 openscad -DPARTNO=1 -o tree.stl model.scad
 openscad -DPARTNO=2 -o trunk.stl model.scad
 openscad -DPARTNO=3 -o base.stl model.scad
 
 # export image of all the parts combined
 openscad -DPARTNO=0 -o model.png model.scad

Running this script once from the command line will export all of the parts to separate files.

我要怎樣做才能導出比當前窗口解像度更高的截圖呢?[編輯]

Right now that is not possible from the GUI as the images are restricted to the actual display context so using the File->Export->Export As Image menu will always export at viewport resolution.

It is however possible to generate higher resolution images via command line using the --imgsize parameter. This uses a separate drawing context to generate the image which is size limited only by memory and the graphics driver. For example on Linux the Mesa driver for Intel UHD Graphics 620 (Kabylake GT2) seems to max out at an image resolution of about 16000x16000.

 $ openscad --imgsize 16000,16000 -o CSG.png CSG.scad
 ECHO: version = [2019, 1, 0]
 Compiling design (CSG Products normalization)...
 Normalized CSG tree has 6 elements
 $ file CSG.png 
 CSG.png: PNG image data, 16000 x 16000, 8-bit/color RGB, non-interlaced

語言問題[編輯]

為什麼我寫下a = a + 1這條語句卻會得到一條錯誤消息?[編輯]

http://forum.openscad.org/A-A-1-tp11385p11411.html

First of all, the question why we have these "limitations" will become more clear once we start better exploiting the opportunities.

  • We need a "reduce" function to help collecting information depending on a list of input. Recursion is fine, but people tend to struggle with it and we could offer some help.
  • We should probable disallow any attempt of reassignment, to make it more clear what's going on. The only real reason we partially allow it is to allow cmd-line variable overrides.

To help think about things:

  • Imagine every expression in OpenCAD being executed in parallel. Any dependency of existing expressions must be made explicit by hierarchical grouping. This will kill the idea of iterating in order to accumulate information.
  • In terms of functions: Imagine a function expression being something you'd type into a spreadsheet cell. Not totally mappable, but it might help framing it.

Now, we could add all kinds of sugar to help people apply their existing programming problem solving skills. Question is more if it really helps us, secondary who will spearhead the design of such language extensions, as we currently don't really have attachment for these ideas on the dev-team.

If you think about the OpenSCAD language as something similar to HTML, but for 3D modeling, you'd still have a need for various programs generating code in this language (similar to the plethora of HTML generators out there). There exist a number of tools for helping with OpenSCAD code generation from existing programming languages (python, ruby, C++, haskell, clojure off the top of my head) and there are tools offering Javascript interfaces for similar purposes (OpenJSCAD, CoffeeSCAD). Until we have a really good reason to do so in OpenSCAD proper, and a really good candidate for which language to support, I think it's better to keep these things separate.


see also for help: List Comprehension, Tips & Tricks, Recursive Functions

用戶界面問題[編輯]

OpenSCAD並不適於我的GTK桌面主題[編輯]

You may need to install package "qt5-style-plugins" on debian based systems, then set environment variable when calling openscad QT_QPA_PLATFORMTHEME=gtk2 openscad

To make the setting permanent, add export QT_QPA_PLATFORMTHEME=gtk2 to your user's ~/.profile

我在Ubuntu系統中運行OpenSCAD時並沒有看到菜單欄,怎樣才能讓她回來?[編輯]

This seems to be caused by Ubuntu messing with Qt to move the menubar somewhere else (e.g. top of the screen).

That problem hits other applications too, see https://bugs.launchpad.net/ubuntu/+source/appmenu-qt5/+bug/1307619

There are two things that could help:

  • Set the QT_QPA_PLATFORMTHEME environment variable to an empty string (the default value is probably "appmenu-qt5") or simply run OpenSCAD with QT_QPA_PLATFORMTHEME= openscad
  • Remove the appmenu-qt5 package to globally disable menubar changes for all applications

為什麼程序給出的錯誤行號是錯的?[編輯]

That is a limitation/bug in the current parser that handles include<> basically as copy&paste of content. In some cases it's possible to work around the issue by placing the include<> statements at the end of the file.

When depending on libraries, it's recommended to use use<> instead which does not have that problem and also automatically inhibits any top-level geometry of that file (which might be there as demo for the library).

我不喜歡OpenSCAD自帶的編輯器,我能用我最喜歡的編輯器取代她嗎?[編輯]

Yes, OpenSCAD supports a special mode that will reload the files if they are modified externally. To enable this mode, check the Design -> Automatic Reload and Preview option and just close the editor window (or use View -> Hide Editor).

As an example, here's a script which runs vim as editor and also starts OpenSCAD which will take the model viewer role.

It supports 3 modes

  • Run with no parameters, it opens a temp file for quick testing, which it deletes.
  • Run with the name of a non-existent file, it starts the file with a default license header.
  • Run with the name of an existing file, it simply opens it.
#!/bin/bash
  
FILE="$1"
AUTHOR="Your Name Here"
YEAR="$(date "+%Y")"
LICENSE="// Created in $YEAR by $AUTHOR.\n// This work is released with CC0 into the public domain.\n// https://creativecommons.org/publicdomain/zero/1.0/"

# increase stack size to allow deeper recursion
ulimit -s 65536

if [ "$FILE" == "" ]
then
  TEMPF=`tempfile -s .scad`
  openscad "$TEMPF" >/dev/null 2>/dev/null &
  vim "$TEMPF"
  rm -f "$TEMPF"
  exit
fi

if [ ! -e "$FILE" ]
then
  echo -e "$LICENSE" >> "$FILE"
fi

openscad "$FILE" >/dev/null 2>/dev/null &
vim "$FILE"

Errors / Problems[編輯]

為什麼我會收到"no top level geometry to render(沒有可用於渲染的頂層幾何體)"這條消息?[編輯]

This can have different reasons, some common ones include

Missing / Commented out module call
module model() {
  cube(20);
}
%model();

Using the % modifier does not only make the part transparent, it's not included in the final render!

Difference / Intersection with wrong translated objects

The easiest way to solve this type of issues is to highlight the objects using the # modifier and see if the objects are placed at the position where they should be.

Importing broken STL files

See Why is my imported STL file only showing up with F5 but not F6?

若OpenSCAD崩潰或被強行終止運行,我未保存的資料會丟失嗎?[編輯]

Before starting a preview or render process, the OpenSCAD editor writes a backup file in case there are unsaved changes.

This file is stored in the users documents folder in a separate directory (e.g. on Linux this is normally $HOME/.local/share/OpenSCAD/backups). The actual path can be checked in the Help->Library Info dialog where it is listed as "Backup Path".

在Windows上點擊"New(新建)"或加載文件時,OpenSCAD奔潰惹[編輯]

在部分裝有Intel圖形驅動的機器上OpenSCAD會崩潰,至於更多細節,請參見https://github.com/openscad/openscad/issues/2442

報告bugs、申請功能等問題[編輯]

我該怎樣報告bugs?[編輯]

Bugs in OpenSCAD are best reported in the github issue tracking system at https://github.com/openscad/openscad/issues. If you are not sure it's a bug, asking on the mailing list/forum can help clarifying things.

Please try searching through the existing issues if the bug was already reported. If you find something similar or if you are unsure, create a new issue, but mention the (possibly) related one.

The bug report should give as much information as possible to help with reproducing it, including but not limited to

  • The OpenSCAD version
  • The Operating System name and version
  • A description of the scenario that produces the issue
  • In case of graphics issues, the OpenGL driver information
  • If possible, a trimmed down script reproducing the issue

Most of the technical version information can be found in menu Help -> Library Info.

我該怎樣申請新的功能?[編輯]

New features or changes/extensions to existing features can be requested in the github issue tracking system at https://github.com/openscad/openscad/issues too.

Please make an effort to clearly explain the new feature / change as detailed as possible. Including some background about why you think this feature would be useful to you and other people helps a lot and increases the chances of it being implemented.

怎樣按我所用的系統來報告OpenSCAD中存在的bugs?[編輯]

Windows[編輯]

The Windows version is currently maintained by the OpenSCAD team, so please use the github issue tracker for reporting bugs.

Mac OSX[編輯]

The Mac OSX version is currently maintained by the OpenSCAD team, so please use the github issue tracker for reporting bugs.

Linux[編輯]

The OpenSCAD versions included in / distributed by the various Linux distributions are usually maintained by people/teams working with the distributions.

Specific bugs can be reported in the respective bug tracking systems, e.g.

The nightly builds hosted on the openSUSE build service are maintained by the OpenSCAD team, so please use the github issue tracker for reporting issues with those packages.