首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >windows powershell中的Inkscape shell循环

windows powershell中的Inkscape shell循环
EN

Stack Overflow用户
提问于 2020-11-09 10:41:03
回答 1查看 404关注 0票数 0

我在中编写了一个简单的脚本来循环一些SVG文件,并在导出之前对页面区域进行调整。这是很好的工作,但相对缓慢。因此,我想尝试使用Inkscape的shell模式,但是对于如何使它工作,我完全感到困惑。我尝试过在这个页面https://inkscape.org/doc/inkscape-man.html中使用的方法,但是没有成功。下面是我的“工作但速度慢”的脚本来展示我想要做的事情:

代码语言:javascript
运行
复制
$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。

代码语言:javascript
运行
复制
$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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-14 23:26:06

正如莫伊尼建议的,请升级你的Inkscape版本。我只能在最新的Inkscape版本1.0.1中完成这项工作:

代码语言:javascript
运行
复制
# 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

我希望这个简短的例子能有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64750047

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档