Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

Batch: pass the data set naming choice in the batch run

dotCooCooc55e4a226ea1
diff --git a/crates/engine/src/cmd/fileio/action_batch.rs b/crates/engine/src/cmd/fileio/action_batch.rs
index 307f43174..565710f9e 100644
--- a/crates/engine/src/cmd/fileio/action_batch.rs
+++ b/crates/engine/src/cmd/fileio/action_batch.rs
@@ -34,6 +34,7 @@ struct Run<'a> {
override_export: bool,
destination: &'a str,
dest_folder: Option<&'a str>,
+ dataset_file_naming: &'a str,
}
/// Play `commands` on each source file or data set.
@@ -90,10 +91,11 @@ pub(super) fn action_batch(s: &mut Session, p: &Value) -> Result<Value> {
override_export: bool_or(p, "overrideExport", true),
destination,
dest_folder: dest_folder.as_deref(),
+ dataset_file_naming: p.get("datasetFileNaming").map_or("fileDataSetName", |v| v.as_str().unwrap_or("")),
};
match source {
"folder" => batch_folder(s, C, p, override_open, &run),
- "datasets" => batch_datasets(s, C, &run, p),
+ "datasets" => batch_datasets(s, C, &run),
_ => Err(bad(C, "`source` must be `folder` or `datasets`")),
}
}
@@ -134,7 +136,7 @@ fn batch_folder(s: &mut Session, cmd: &str, p: &Value, override_open: bool, run:
}
#[cfg(not(target_arch = "wasm32"))]
-fn batch_datasets(s: &mut Session, cmd: &str, run: &Run<'_>, p: &Value) -> Result<Value> {
+fn batch_datasets(s: &mut Session, cmd: &str, run: &Run<'_>) -> Result<Value> {
let st = s.doc()?;
let names: Vec<String> = st.doc.variables.datasets.iter().map(|d| d.name.clone()).collect();
if names.is_empty() {
@@ -144,8 +146,7 @@ fn batch_datasets(s: &mut Session, cmd: &str, run: &Run<'_>, p: &Value) -> Resul
return Err(bad(cmd, format!("more than {MAX_BATCH_FILES} data sets")));
}
let doc_stem = st.path.as_deref().and_then(|p| std::path::Path::new(p).file_stem().and_then(|s| s.to_str())).unwrap_or("Untitled").to_string();
- let naming = p.get("datasetFileNaming").map_or("fileDataSetName", |v| v.as_str().unwrap_or(""));
- let stems = dataset_stems(&names, &doc_stem, naming, run)?;
+ let stems = dataset_stems(&names, &doc_stem, run.dataset_file_naming, run)?;
let steps = filter_steps(run.steps, true, false);
let run = Run { steps: &steps, ..*run };
let mut processed = Vec::new();
@@ -690,6 +691,7 @@ mod tests {
override_export: true,
destination: "none",
dest_folder: None,
+ dataset_file_naming: "fileDataSetName",
};
let stems = dataset_stems(&names, "source", "fileNumber", &run).unwrap();
for n in [1, 2, 10, 100, 500] {
@@ -714,6 +716,7 @@ mod tests {
override_export: true,
destination: "none",
dest_folder: None,
+ dataset_file_naming: "fileDataSetName",
};
assert_eq!(dataset_stems(&[String::new()], "Untitled", "dataSetName", &run).unwrap(), ["Untitled001"]);
assert_eq!(dataset_stems(&[" ".to_string()], "Untitled", "dataSetName", &run).unwrap(), ["Untitled001"]);
@@ -780,6 +783,7 @@ mod tests {
override_export: true,
destination: "none",
dest_folder: Some(&folder),
+ dataset_file_naming: "fileDataSetName",
};
crate::file_access::confine(Some(&roots), || {
assert_eq!(dataset_stems(&["Alpha".into()], "source", "dataSetName", &run).unwrap(), ["Alpha"]);
@@ -815,6 +819,7 @@ mod tests {
override_export: true,
destination: "none",
dest_folder: Some(&folder),
+ dataset_file_naming: "fileDataSetName",
};
assert_eq!(
dataset_stems(&["Alpha".into()], "source", "dataSetName", &run).unwrap_or_else(|e| panic!("{format}: {e}")),
@@ -840,6 +845,7 @@ mod tests {
override_export: true,
destination: "none",
dest_folder: Some(&folder),
+ dataset_file_naming: "fileDataSetName",
};
assert_eq!(dataset_stems(&[".".into(), "..".into()], ".", "dataSetName", &run).unwrap(), ["Untitled001", "Untitled002"]);
assert_eq!(dataset_stems(&["Alpha".into()], "..", "fileNumber", &run).unwrap(), ["Untitled001"]);
diff --git a/docs/mcp.md b/docs/mcp.md
index 996cee88b..bee6b9681 100644
--- a/docs/mcp.md
+++ b/docs/mcp.md
@@ -1622,15 +1622,12 @@ already walks Image Trace. Short agent entry points:
`%`). A declaration that holds anything else, and entity references that expand the library past 8 MiB, are
refused. So are a variable or data set declared twice and a value for a variable the library doesn't declare.
- Batch: `action.batch {commands, source?: folder|datasets, folder?, destination?: none|saveAndClose|folder,
- destinationFolder?, datasetFileNaming?: fileNumber|fileDataSetName|dataSetName, overrideOpen?,
- overrideSave?, overrideExport?, includeSubdirs?, stopOnError?}` plays an action on every file in a
- folder or every data set (the Actions panel menu's Batch…). Override Save and Override Export end
- the file name of a step with `format` in that `format`, in lower case and without a leading dot,
- when it is one of the format's extensions (`.svg` and `SVG` give `.svg`, `.JPEG` gives `.jpeg`),
- and otherwise in the format's first extension (`png8` gives `.png`, `template` gives `.vctemplate`).
- A step without `format` keeps the source file's extension (`.vectorcraft` over data sets).
- An output already in a destination folder gets the next free `-2`, `-3` suffix only when the batch
- may read and write that folder.
+ destinationFolder?, overrideOpen?, overrideSave?, overrideExport?, includeSubdirs?, stopOnError?}` plays an
+ action on every file in a folder or every data set (the Actions panel menu's Batch…). Override Save and Override
+ Export end the file name of a step with `format` in that `format`, in lower case and without a leading dot, when it
+ is one of the format's extensions (`.svg` and `SVG` give `.svg`, `.JPEG` gives `.jpeg`), and otherwise in the
+ format's first extension (`png8` gives `.png`, `template` gives `.vctemplate`). A step without `format` keeps the
+ source file's extension (`.vectorcraft` over data sets).
- Image Trace: `imageTrace.presets`, `imageTrace.make {id?, preset?, params?, view?}` (or `imageTrace.makeAndExpand`),
`imageTrace.setView`, `imageTrace.expand`, `imageTrace.release`. A key inside `params` that is not one of the trace
settings, such as `colours`, is an error that names it and the nearest setting (`colors`), as for a command's own keys.
@@ -2967,15 +2964,15 @@ remote mode, MCP's `run_command` calls and each step of the `command_batch` tool
Actions panel plays an action as a `command.batch`. The Actions panel menu's Batch… runs
`action.batch`: the same steps on every readable file in a folder (or every data set of the open document), with
destination `none` | `saveAndClose` | `folder` and Override Open / Save / Export. For a Data Sets source,
-`datasetFileNaming` chooses File + Number (`source001`), File + Data Set Name (`source_Alpha`), or Data Set Name
-(`Alpha`). An omitted parameter keeps File + Data Set Name for existing callers; the dialog starts with File +
-Number. A folder source ignores this parameter. The folder destination and overridden Save/Export paths use the
-chosen stem with the output format's extension. An empty data set name under Data Set Name falls back to the
-document stem plus its three-digit ordinal.
-Batch writes `/`, `\`, `:`, `<`, `>`, `"`, `|`, `?`, `*` and control characters in the data set's name as `-`, and
-adds the next free `-2`, `-3` suffix to a stem already used in the batch or whose generated output path exists in
-a destination folder the batch may read and write before it starts. Under Data Set Name, VectorCraft also makes
-Windows device names safe (`CON` becomes `CON-`). This is VectorCraft's naming behavior. Caps: 500
+`datasetFileNaming?: fileNumber | fileDataSetName | dataSetName` chooses File + Number (`source001`),
+File + Data Set Name (`source_Alpha`), or Data Set Name (`Alpha`). An omitted parameter keeps File + Data Set Name
+for existing callers; the dialog starts with File + Number. A folder source ignores this parameter. The folder
+destination and overridden Save/Export paths use the chosen stem with the output format's extension. An empty data
+set name under Data Set Name falls back to the document stem plus its three-digit ordinal. Batch writes `/`, `\`,
+`:`, `<`, `>`, `"`, `|`, `?`, `*` and control characters in the data set's name as `-`, and adds the next free `-2`,
+`-3` suffix to a stem already used in the batch (compared without case). An output already in a destination folder
+gets the next free suffix only when the batch may read and write that folder before it starts. Under Data Set Name,
+VectorCraft makes Windows device names safe (`CON` becomes `CON-`). This is VectorCraft's naming behavior. Caps: 500
files or data sets, 8 folder levels, 256 steps. An action recorded in the Actions panel leaves the artboard out,
and its steps of these commands get the artboard that is active when the action plays. A press with the Selection,
Direct Selection or Group Selection tool inside an artboard makes that artboard the active one; with the Selection