我应该如何将值传递给命令行的OpenSCAD?

发布于 2025-01-31 16:52:28 字数 5063 浏览 4 评论 0原文

我想在一堆STL文件上应用一定的修改。因此,我编写了一个OpenScad程序,并想从命令行脚本进行脚本,但它不起作用,我不知道为什么。

根据人页面,我认为以下命令会起作用,但行不通(啊,我也使用openscad的附属版本(如果很重要

OpenSCAD-2021.01-x86_64.AppImage -o [OUTPUT FILE NAME] 'myscript.scad' -D filename=[INPUT FILE NAME] 

) 的。

echo ("START");

filename1="cube.stl";

echo(filename1=filename1, filename2=filename2);

minkowski() {
  import(filename1);
  sphere(r=1, $fn=24);
}

translate([30, 0, 0])
  minkowski() {
    import(filename2);
    sphere(r=1, $fn=24);
  }

我期望

Compiling design (CSG Tree generation)...
ECHO: "START"
WARNING: Ignoring unknown variable 'filename2' in file test.scad, line 5 
ECHO: filename1 = "cube.stl", filename2 = undef
WARNING: Ignoring unknown variable 'filename2' in file test.scad, line 14 
Compiling design (CSG Products generation)...
ERROR: Unsupported file format while trying to import file '""', import() at line 14 
Geometries in cache: 5
Geometry cache size in bytes: 128056
CGAL Polyhedrons in cache: 0
CGAL cache size in bytes: 0
Compiling design (CSG Products normalization)...
Normalized tree has 2 elements!
Compile and preview finished.
Total rendering time: 0:00:00.177

t做 它在命令行中,没有初始化的值,顺便说一句,我不知道我的SCAD文件只有16行:

MyPrompt> ./OpenSCAD-2021.01-x86_64.AppImage -o 'test.stl' 'test.scad' -D filename1=cube.stl -D filename2=cube.stl 
WARNING: Ignoring unknown variable 'cube' in file test.scad, line 19
WARNING: Ignoring unknown variable 'cube' in file test.scad, line 20
ECHO: "START"
ECHO: filename1 = undef, filename2 = undef
ERROR: Unsupported file format while trying to import file '""', import() at line 8
Geometries in cache: 4
Geometry cache size in bytes: 118112
CGAL Polyhedrons in cache: 1
CGAL cache size in bytes: 1362752
Total rendering time: 0:00:00.854
   Top level object is a 3D object:
   Simple:        yes
   Vertices:      576
   Halfedges:    3168
   Edges:        1584
   Halffacets:   2024
   Facets:       1012
   Volumes:         3

Cube.stl是用cube(); 命令和包含:

00000000  4f 70 65 6e 53 43 41 44  20 4d 6f 64 65 6c 0a 00  |OpenSCAD Model..|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000050  0c 00 00 00 00 00 00 80  00 00 00 00 00 00 80 3f  |...............?|
00000060  00 00 00 00 00 00 80 3f  00 00 80 3f 00 00 80 3f  |.......?...?...?|
*
00000080  00 00 80 3f 00 00 00 00  00 00 00 00 00 00 00 00  |...?............|
00000090  80 3f 00 00 80 3f 00 00  00 00 00 00 80 3f 00 00  |.?...?.......?..|
000000a0  00 00 00 00 80 3f 00 00  80 3f 00 00 00 00 00 00  |.....?...?......|
000000b0  00 00 00 00 80 3f 00 00  00 00 00 00 00 00 00 00  |.....?..........|
000000c0  00 00 80 bf 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000d0  00 00 80 3f 00 00 80 3f  00 00 00 00 00 00 80 3f  |...?...?.......?|
000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 80 00 00  |................|
000000f0  00 00 00 00 80 bf 00 00  80 3f 00 00 80 3f 00 00  |.........?...?..|
00000100  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000110  00 00 00 00 80 3f 00 00  00 00 00 00 00 00 00 00  |.....?..........|
00000120  00 00 80 bf 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000130  00 00 00 00 00 00 80 3f  00 00 00 00 00 00 80 3f  |.......?.......?|
00000140  00 00 00 00 00 00 00 00  00 00 80 3f 00 00 00 00  |...........?....|
00000150  00 00 00 00 80 bf 00 00  00 80 00 00 80 3f 00 00  |.............?..|
00000160  00 00 00 00 80 3f 00 00  00 00 00 00 00 00 00 00  |.....?..........|
*
00000180  00 00 80 3f 00 00 00 80  00 00 00 00 00 00 80 3f  |...?...........?|
00000190  00 00 00 00 00 00 80 3f  00 00 80 3f 00 00 80 3f  |.......?...?...?|
*
000001b0  00 00 00 00 80 3f 00 00  00 00 00 00 00 00 00 00  |.....?..........|
000001c0  80 3f 00 00 80 3f 00 00  00 00 00 00 80 3f 00 00  |.?...?.......?..|
000001d0  00 00 00 00 80 3f 00 00  80 3f 00 00 00 00 00 00  |.....?...?......|
000001e0  00 00 00 00 00 00 00 00  00 00 80 3f 00 00 00 80  |...........?....|
000001f0  00 00 80 3f 00 00 80 3f  00 00 00 00 00 00 00 00  |...?...?........|
00000200  00 00 80 3f 00 00 80 3f  00 00 80 3f 00 00 80 3f  |...?...?...?...?|
00000210  00 00 80 3f 00 00 00 00  00 00 00 00 80 3f 00 00  |...?.........?..|
00000220  00 00 00 00 00 00 00 00  80 3f 00 00 80 3f 00 00  |.........?...?..|
00000230  80 3f 00 00 80 3f 00 00  00 00 00 00 00 00 00 00  |.?...?..........|
00000240  80 3f 00 00 00 00 00 00  00 00 80 bf 00 00 00 00  |.?..............|
00000250  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000260  00 00 00 00 00 00 80 3f  00 00 80 3f 00 00 00 00  |.......?...?....|
00000270  00 00 80 3f 00 00 00 00  00 00 00 00 80 bf 00 00  |...?............|
00000280  00 80 00 00 00 00 00 00  00 00 00 00 80 3f 00 00  |.............?..|
00000290  80 3f 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |.?..............|
000002a0  00 00 00 00 00 00 00 00  80 3f 00 00              |.........?..|

I want to apply a certain modification on a bunch of stl files. So I wrote an openSCAD program and wanted to script from the command line, but it doesn't work and I can't figure out why.

According to the man page, I thought the following command would work but it doesn't (Ah, also I use an appimage version of openSCAD (for in case it would be important):

OpenSCAD-2021.01-x86_64.AppImage -o [OUTPUT FILE NAME] 'myscript.scad' -D filename=[INPUT FILE NAME] 

However, it appears, the -D options doesn't do what I expect. So I made a little test script:

echo ("START");

filename1="cube.stl";

echo(filename1=filename1, filename2=filename2);

minkowski() {
  import(filename1);
  sphere(r=1, $fn=24);
}

translate([30, 0, 0])
  minkowski() {
    import(filename2);
    sphere(r=1, $fn=24);
  }

If I test myscript.scad with the gui version of openSCAD, it gives the following result (which is expected):

Compiling design (CSG Tree generation)...
ECHO: "START"
WARNING: Ignoring unknown variable 'filename2' in file test.scad, line 5 
ECHO: filename1 = "cube.stl", filename2 = undef
WARNING: Ignoring unknown variable 'filename2' in file test.scad, line 14 
Compiling design (CSG Products generation)...
ERROR: Unsupported file format while trying to import file '""', import() at line 14 
Geometries in cache: 5
Geometry cache size in bytes: 128056
CGAL Polyhedrons in cache: 0
CGAL cache size in bytes: 0
Compiling design (CSG Products normalization)...
Normalized tree has 2 elements!
Compile and preview finished.
Total rendering time: 0:00:00.177

However, if I test it in command line, no value is initialized, and by the way, I have no idea what are both those warning on line 19 and 20 while my scad file only has 16 lines:

MyPrompt> ./OpenSCAD-2021.01-x86_64.AppImage -o 'test.stl' 'test.scad' -D filename1=cube.stl -D filename2=cube.stl 
WARNING: Ignoring unknown variable 'cube' in file test.scad, line 19
WARNING: Ignoring unknown variable 'cube' in file test.scad, line 20
ECHO: "START"
ECHO: filename1 = undef, filename2 = undef
ERROR: Unsupported file format while trying to import file '""', import() at line 8
Geometries in cache: 4
Geometry cache size in bytes: 118112
CGAL Polyhedrons in cache: 1
CGAL cache size in bytes: 1362752
Total rendering time: 0:00:00.854
   Top level object is a 3D object:
   Simple:        yes
   Vertices:      576
   Halfedges:    3168
   Edges:        1584
   Halffacets:   2024
   Facets:       1012
   Volumes:         3

For reference the cube.stl was made with the cube(); command and contains:

00000000  4f 70 65 6e 53 43 41 44  20 4d 6f 64 65 6c 0a 00  |OpenSCAD Model..|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000050  0c 00 00 00 00 00 00 80  00 00 00 00 00 00 80 3f  |...............?|
00000060  00 00 00 00 00 00 80 3f  00 00 80 3f 00 00 80 3f  |.......?...?...?|
*
00000080  00 00 80 3f 00 00 00 00  00 00 00 00 00 00 00 00  |...?............|
00000090  80 3f 00 00 80 3f 00 00  00 00 00 00 80 3f 00 00  |.?...?.......?..|
000000a0  00 00 00 00 80 3f 00 00  80 3f 00 00 00 00 00 00  |.....?...?......|
000000b0  00 00 00 00 80 3f 00 00  00 00 00 00 00 00 00 00  |.....?..........|
000000c0  00 00 80 bf 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000d0  00 00 80 3f 00 00 80 3f  00 00 00 00 00 00 80 3f  |...?...?.......?|
000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 80 00 00  |................|
000000f0  00 00 00 00 80 bf 00 00  80 3f 00 00 80 3f 00 00  |.........?...?..|
00000100  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000110  00 00 00 00 80 3f 00 00  00 00 00 00 00 00 00 00  |.....?..........|
00000120  00 00 80 bf 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000130  00 00 00 00 00 00 80 3f  00 00 00 00 00 00 80 3f  |.......?.......?|
00000140  00 00 00 00 00 00 00 00  00 00 80 3f 00 00 00 00  |...........?....|
00000150  00 00 00 00 80 bf 00 00  00 80 00 00 80 3f 00 00  |.............?..|
00000160  00 00 00 00 80 3f 00 00  00 00 00 00 00 00 00 00  |.....?..........|
*
00000180  00 00 80 3f 00 00 00 80  00 00 00 00 00 00 80 3f  |...?...........?|
00000190  00 00 00 00 00 00 80 3f  00 00 80 3f 00 00 80 3f  |.......?...?...?|
*
000001b0  00 00 00 00 80 3f 00 00  00 00 00 00 00 00 00 00  |.....?..........|
000001c0  80 3f 00 00 80 3f 00 00  00 00 00 00 80 3f 00 00  |.?...?.......?..|
000001d0  00 00 00 00 80 3f 00 00  80 3f 00 00 00 00 00 00  |.....?...?......|
000001e0  00 00 00 00 00 00 00 00  00 00 80 3f 00 00 00 80  |...........?....|
000001f0  00 00 80 3f 00 00 80 3f  00 00 00 00 00 00 00 00  |...?...?........|
00000200  00 00 80 3f 00 00 80 3f  00 00 80 3f 00 00 80 3f  |...?...?...?...?|
00000210  00 00 80 3f 00 00 00 00  00 00 00 00 80 3f 00 00  |...?.........?..|
00000220  00 00 00 00 00 00 00 00  80 3f 00 00 80 3f 00 00  |.........?...?..|
00000230  80 3f 00 00 80 3f 00 00  00 00 00 00 00 00 00 00  |.?...?..........|
00000240  80 3f 00 00 00 00 00 00  00 00 80 bf 00 00 00 00  |.?..............|
00000250  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000260  00 00 00 00 00 00 80 3f  00 00 80 3f 00 00 00 00  |.......?...?....|
00000270  00 00 80 3f 00 00 00 00  00 00 00 00 80 bf 00 00  |...?............|
00000280  00 80 00 00 00 00 00 00  00 00 00 00 80 3f 00 00  |.............?..|
00000290  80 3f 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |.?..............|
000002a0  00 00 00 00 00 00 00 00  80 3f 00 00              |.........?..|

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

℉絮湮 2025-02-07 16:52:28

好的,明白了:

问题来自OpenScad想要接收带有引号的字符串的事实。但是,贝壳会尝试吃它们。因此,正确的调用语法将是:

MyPrompt> ./Téléchargements/OpenSCAD-2021.01-x86_64.AppImage -o 'test.stl' 'test.scad' -D filename1='"cube.stl"' -D filename2='"cube.stl"'
ECHO: "START"
ECHO: filename1 = "cube.stl", filename2 = "cube.stl"
Geometries in cache: 4
Geometry cache size in bytes: 136832
CGAL Polyhedrons in cache: 1
CGAL cache size in bytes: 1524416
Total rendering time: 0:00:01.021
   Top level object is a 3D object:
   Simple:        yes
   Vertices:      672
   Halfedges:    3536
   Edges:        1768
   Halffacets:   2200
   Facets:       1100
   Volumes:         3

这也解释了警告,因为它不是尝试将cube.stl将其解释为字符串,而是DOT符号中的变量名称(因此,主要变量名称确实是Cube)。

Ok, Got it :

The problem comes from the fact that openSCAD wants to receive string with the quotation marks. However, the shell will try to eat them. So, the correct calling syntax will be :

MyPrompt> ./Téléchargements/OpenSCAD-2021.01-x86_64.AppImage -o 'test.stl' 'test.scad' -D filename1='"cube.stl"' -D filename2='"cube.stl"'
ECHO: "START"
ECHO: filename1 = "cube.stl", filename2 = "cube.stl"
Geometries in cache: 4
Geometry cache size in bytes: 136832
CGAL Polyhedrons in cache: 1
CGAL cache size in bytes: 1524416
Total rendering time: 0:00:01.021
   Top level object is a 3D object:
   Simple:        yes
   Vertices:      672
   Halfedges:    3536
   Edges:        1768
   Halffacets:   2200
   Facets:       1100
   Volumes:         3

This also explains the warnings, because it wasn't try to interpret cube.stl as a string, but as a variable name in dot notation (so the main variable name was indeed cube).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文