OpenSCAD 使用者手冊/WIP/遷移指南
外觀
< OpenSCAD 使用者手冊 | WIP
OpenSCAD 2019 包含了一些破壞舊設計或對之前沒有錯誤和警告的程式碼產生錯誤和警告的更改。
在以下情況下,OpenSCAD 2019 會在重複賦值的情況下產生警告
- 在同一個檔案和範圍內覆蓋變數
- 主檔案中的賦值被包含檔案覆蓋
在以下情況下,變數會由最後一個賦值靜默覆蓋
- 透過命令列賦值
- 包含檔案中的變數被主檔案覆蓋
這段程式碼現在會導致警告,因為 $test 沒有被初始化
test = $test==undef ? 1 : $test ;
解決方法是使用新的 is_undef() 函式
test = is_undef($test) ? 1 : $test ;
內建函式和模組現在會在引數型別不匹配時發出警告。
由於型別檢查以前是透過使用內建函式返回 undef 來完成的,因此現在建議/要求使用 is_list()、is_num()、is_bool() 和 is_string() 來進行型別檢查。
OpenSCAD 2019 會在多次提供命名引數時發出警告。
cube(size=2,size=1);
OpenSCAD 現在會在模組或函式引數未宣告時發出警告。
這意味著現在會導致警告
a=1;
module test(){
cube(a);
}
test();
translate([2,0,0])
test(a=2);
如果您打算這樣做 - 比如在 Write.scad 庫中 - 您可以按如下方式更新程式碼
a=1;
module test(a){
cube(a);
}
test();
translate([2,0,0])
test(a=2);
對於 Write.scad,具體來說:像這樣的定義
module writecircle(text,where,radius){
需要更改為
module writecircle(text, where, radius, rotate, font, h, t, spac, east, west, middle, ccw){
</syntaxhighlight lang="unknown">
==== builtin modules ====
Same goes for builtin modules, so this now creates a warning:
<syntaxhighlight lang="text">
sphere(center=true);
以及
circle(center=true);
circle 和 sphere 都不支援 center 引數 - circle 和 sphere 始終居中。
另一個例子是
circle(radius=5);
因為 circle 接受 r,而不是 radius。
module test(a){
a=2;
sphere(a);
}
test();
translate([4,0,0])
test(a=1);
請注意,這個非常類似的示例不會觸發警告,因為實現中有缺陷
module test(a){
a=1+1;
sphere(a);
}
test();
translate([4,0,0])
test(a=2);
像這樣的
cube(-1);
cube([1,1,-1]);
cube(0);
cube([1,1,0]);
cylinder(h = 1, r1 = 0, r2 = 1, d = 2, center = true);
如果內建函式的引數計數不匹配,OpenSCAD 2019 會顯示警告
echo(abs(123,456));
內建 Assert 不能被使用者函式或模組覆蓋。如果您有一個名為 assert 的函式或模組,則必須重新命名它。