我在中编写了一个简单的脚本来循环一些SVG文件,并在导出之前对页面区域进行调整。这是很好的工作,但相对缓慢。因此,我想尝试使用Inkscape的shell模式,但是对于如何使它工作,我完全感到困惑。我尝试过在这个页面https://inkscape.org/doc/inkscape-man.html中使用的方法,但是没有成功。下面是我的“工作但速度慢”的脚本来展示我想要做的事情:
$files = Get-ChildItem "C:\temp\SVG Charts" -filter *.svg
# Starts a FOR loop which runs through each of the files from above
foreach ($f in $files){
# Prepare the name of the outputted file
# So you don't save over the originals
$outfile = $f.DirectoryName + "\Adjusted_" + $f.BaseName + ".svg"
# Run inkscape
# The export-area-drawing command below simply resets the print area of the SVG
inkscape $f.FullName --export-area-drawing --export-plain-svg $outfile
}下面是我对shell版本的尝试。我认为循环结构不正确,需要将inkscape --shell放在循环之外,但是它只是挂起,等待输入。如果我把它放在循环中,那么就会提示我在每次迭代中输入put,然后显示大量的红色错误文本,我认为这可能与下一个点有关.似乎有几种不同的编写shell命令的方法,我不知道我是否使用了正确的方法!我很难解决最后一点,因为我不知道我是否以正确的方式设置了循环来使用shell。
$files = Get-ChildItem "C:\temp\SVG Charts" -filter *.svg
# Starts a FOR loop which runs through each of the files from above
foreach ($f in $files){
# Prepare the name of the outputted file
# So you don't save over the originals
$outfile = $f.DirectoryName + "\Adjusted_" + $f.BaseName + ".svg"
# The export-area-drawing command below simply resets the print area of the SVG
inkscape --shell
file-open:$f.FullName; export-area-drawing; export-filename:$outfile; export-do
}我的问题是:我应该如何构造这个Powershell循环,我应该使用什么语法来运行命令?
我正在运行一个相对较旧的Inkscape版本,它无疑没有帮助: Inkscape 0.92.3
发布于 2020-11-14 23:26:06
正如莫伊尼建议的,请升级你的Inkscape版本。我只能在最新的Inkscape版本1.0.1中完成这项工作:
# Avoid specifying long file paths in Inkscape commands...
Set-Location -Path 'C:\Temp\SVG Charts'
# Build-up a list of actions to send to Inkscape...
[string]$actions = ''
$files = Get-ChildItem -Filter *.svg
foreach ($f in $files) {
$actions += "file-open:$($f.Name); export-area-drawing; export-filename:Adjusted_$($f.Name); export-do`r`n"
}
# Ensure to end your list of actions with 'quit', then pipe it to Inkscape...
"$actions`r`nquit" | & "C:\Program Files\Inkscape\bin\inkscape.com" --shell我希望这个简短的例子能有所帮助。
https://stackoverflow.com/questions/64750047
复制相似问题