You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Windows PowerShell中正确编写Inkscape Shell批量SVG处理脚本?

Optimizing Inkscape Batch Processing in PowerShell Using Shell Mode (Inkscape 0.92.3)

Your original script is slow because it launches a new Inkscape process for every SVG file—this adds significant overhead. The key to fixing this is to run one instance of Inkscape in shell mode and send all your processing commands to it, instead of spawning a new process each time.

Correct PowerShell Script Using Inkscape Shell Mode

Here's the optimized script tailored for Inkscape 0.92.3, which maintains a single Inkscape shell session and processes all files sequentially:

# Get all SVG files in the target directory
$files = Get-ChildItem "C:\temp\SVG Charts" -Filter *.svg

# Build a list of Inkscape shell commands for each file
$inkscapeCommands = foreach ($f in $files) {
    # Safely construct the output path (avoids manual string concatenation errors)
    $outFile = Join-Path -Path $f.DirectoryName -ChildPath "Adjusted_$($f.BaseName).svg"
    
    # Inkscape 0.92.3 shell command syntax: wrap paths with quotes to handle spaces
    "file-open:`"$($f.FullName)`"; export-area-drawing; export-plain-svg:`"$outFile`";"
}

# Add the quit command to exit Inkscape shell when done
$inkscapeCommands += "quit;"

# Pipe all commands to the single Inkscape shell instance
$inkscapeCommands | inkscape --shell

Why Your Previous Attempt Failed

Let's break down the issues in your shell mode script:

  1. Repeatedly launching Inkscape shell: Putting inkscape --shell inside the loop spawns a new Inkscape process for every file—this defeats the purpose of shell mode and causes errors from unclosed sessions.
  2. Incorrect command syntax: Inkscape 0.92.3 doesn't use the export-filename/export-do workflow (that's a newer 1.0+ feature). Instead, export-plain-svg accepts the output filename directly as an argument.
  3. Unquoted paths: If your file paths contain spaces (like your directory "SVG Charts"), Inkscape will misparse them unless wrapped in quotes.

Key Notes for Inkscape 0.92.3 Shell Mode

  • Single session only: Always launch inkscape --shell once, then send all commands to it via stdin (the pipe in PowerShell).
  • Command formatting: Separate commands with semicolons, and wrap paths with double quotes to handle spaces.
  • Order matters: For each file, you must:
    1. Open the file with file-open:"path"
    2. Adjust the area with export-area-drawing
    3. Export with export-plain-svg:"output-path"

This approach will drastically speed up your batch processing since you're only initializing Inkscape once, not per file.

内容的提问来源于stack exchange,提问作者Tumbledown

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 20:32:40