mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge #15201 into the merge queue batch
Layers to Files: one file per layer inside a group, none for the group
This commit is contained in:
commit
0ea5307093
5 files changed
+302
-23
No files matched your search
@@ -869,7 +869,7 @@ impl PhotocraftMcp {
|
||||
}
|
||||
|
||||
#[tool(
|
||||
description = "Export top-level layers as files (groups merged). Returns files and skipped: [{layer, name, reason}] for hidden layers (visible_only) and adjustments with no pixels of their own. Workspace exports resolve beneath the write root, also return count of written files, and reject existing files instead of overwriting them. Trusted-local/bridge exports use the engine command's file access policy."
|
||||
description = "Export each layer as a file; groups are walked (a group gets no file, each layer in it does, named <prefix>_<group index>s_<index>_<name>). Returns files and skipped: [{layer, name, reason}] for hidden layers (visible_only, including the layers of a hidden group) and adjustments with no pixels of their own. Workspace exports resolve beneath the write root, also return count of written files, and reject existing files instead of overwriting them. Trusted-local/bridge exports use the engine command's file access policy."
|
||||
)]
|
||||
async fn doc_export_layers(&self, Parameters(p): Parameters<ExportLayersParams>) -> Result<CallToolResult, McpError> {
|
||||
let mut opts = serde_json::Map::new();
|
||||
|
||||
@@ -47,9 +47,14 @@ pub struct LayerExportReport {
|
||||
pub skipped: Vec<SkippedExportLayer>,
|
||||
}
|
||||
|
||||
/// The same export as [`export_layers_with`], with an explanation for every omitted top-level
|
||||
/// layer. Groups export merged, so their children are not separate exports or skips. Encoding
|
||||
/// and write failures remain errors, never successful skips. Existing numbering is preserved.
|
||||
/// The same export as [`export_layers_with`], with an explanation for every omitted layer.
|
||||
/// Groups are walked, as the reference walks them (#13957): a group gets no file, every layer in
|
||||
/// it does, named `<prefix>_<group index>s_<index in group>_<name>` (one `<index>s_` per level,
|
||||
/// so two groups deep is `<prefix>_0000s_0000s_0000_<name>`). Art layers and groups are counted
|
||||
/// separately at each level, top to bottom; a skipped layer keeps its number (#13959). With
|
||||
/// `visibleOnly`, the layers of a hidden group are skipped; without it they are exported. A
|
||||
/// layer's file keeps it inside its groups. Encoding and write failures remain errors, never
|
||||
/// successful skips.
|
||||
pub fn export_layers_report_with(s: &Session, p: &Value, mut write: impl FnMut(&str, &[u8]) -> Result<()>) -> Result<LayerExportReport> {
|
||||
let cmd = "file.export.layersToFiles";
|
||||
let format = p.get("format").and_then(Value::as_str).unwrap_or("png").trim_start_matches('.').to_ascii_lowercase();
|
||||
@@ -78,21 +83,40 @@ pub fn export_layers_report_with(s: &Session, p: &Value, mut write: impl FnMut(&
|
||||
std::sync::Arc::make_mut(&mut doc).icc_profile = Some(profile);
|
||||
}
|
||||
let mut report = LayerExportReport::default();
|
||||
// Every layer takes its panel-order index, even one skipped as hidden or as an adjustment,
|
||||
// so a file keeps the same number whether Visible Layers Only is on or off (#13959).
|
||||
for (index, l) in doc.layers.iter().rev().enumerate() {
|
||||
if !l.visible && visible_only {
|
||||
report.skipped.push(SkippedExportLayer { layer: l.id.0, name: l.name.clone(), reason: "hidden by visibleOnly" });
|
||||
continue;
|
||||
}
|
||||
if matches!(l.content, LayerContent::Adjustment(_)) {
|
||||
report.skipped.push(SkippedExportLayer { layer: l.id.0, name: l.name.clone(), reason: "adjustment layer has no pixels of its own" });
|
||||
continue;
|
||||
let mut planned = Vec::new();
|
||||
plan_layer_exports(&doc.layers, &mut Vec::new(), "", visible_only, &mut planned, &mut report.skipped)?;
|
||||
// PNG file names use dashes for spaces (measured); the other formats keep them.
|
||||
let part = |text: &str| if format == "png" { sanitize(text).replace(' ', "-") } else { sanitize(text) };
|
||||
// The prefix is optional; only the layer name needs the empty-name fallback.
|
||||
let prefix_part = if prefix.is_empty() { String::new() } else { part(&prefix) };
|
||||
let file_name = |l: &Layer, number: &str| format!("{prefix_part}_{number}_{}.{format}", part(&l.name));
|
||||
// Every name is known before anything is encoded: one that no file system takes (each group level adds
|
||||
// 6 bytes, so about 41 nested groups pass 255) fails the export before the first file is written.
|
||||
for PlannedLayer { l, number, .. } in &planned {
|
||||
let name = file_name(l, number);
|
||||
if name.len() > MAX_FILE_NAME_BYTES {
|
||||
return Err(EngineError::Other(format!(
|
||||
"Layers to Files: the file name for layer \"{}\" is {} bytes, more than the {MAX_FILE_NAME_BYTES} a file name can hold; shorten the layer or prefix name or nest it in fewer groups",
|
||||
l.name,
|
||||
name.len()
|
||||
)));
|
||||
}
|
||||
}
|
||||
for PlannedLayer { l, groups, number } in planned {
|
||||
let mut one = (*doc).clone();
|
||||
let mut only = l.clone();
|
||||
only.visible = true;
|
||||
only.clipped = false;
|
||||
// The layer stays inside its groups (each shown, holding only the next one in).
|
||||
for group in groups.iter().rev() {
|
||||
let mut g = (*group).clone();
|
||||
g.visible = true;
|
||||
g.clipped = false;
|
||||
if let Some(children) = g.children_mut() {
|
||||
*children = vec![only];
|
||||
}
|
||||
only = g;
|
||||
}
|
||||
one.layers = vec![only].into();
|
||||
if trim {
|
||||
let mut bounds = Rect::EMPTY;
|
||||
@@ -112,11 +136,7 @@ pub fn export_layers_report_with(s: &Session, p: &Value, mut write: impl FnMut(&
|
||||
}
|
||||
}
|
||||
|
||||
// PNG file names use dashes for spaces (measured); the other formats keep them.
|
||||
let part = |text: &str| if format == "png" { sanitize(text).replace(' ', "-") } else { sanitize(text) };
|
||||
// The prefix is optional; only the layer name needs the empty-name fallback.
|
||||
let prefix_part = if prefix.is_empty() { String::new() } else { part(&prefix) };
|
||||
let name = format!("{prefix_part}_{:04}_{}.{format}", index, part(&l.name));
|
||||
let name = file_name(l, &number);
|
||||
let save = include_icc(&mut one, &format, icc, save);
|
||||
let (bytes, _warnings) = encode(&one, &name, save)?;
|
||||
write(&name, &bytes)?;
|
||||
@@ -125,6 +145,76 @@ pub fn export_layers_report_with(s: &Session, p: &Value, mut write: impl FnMut(&
|
||||
Ok(report)
|
||||
}
|
||||
|
||||
/// How deep [`plan_layer_exports`] follows groups before refusing the document.
|
||||
const MAX_GROUP_DEPTH: usize = 128;
|
||||
|
||||
/// The longest file name, in bytes, that common file systems (ext4, APFS, NTFS) take.
|
||||
const MAX_FILE_NAME_BYTES: usize = 255;
|
||||
|
||||
/// One layer Layers to Files writes: the layer, its groups (outermost first) and its number
|
||||
/// (`0000s_0001` for the second art layer of the first group).
|
||||
struct PlannedLayer<'a> {
|
||||
l: &'a Layer,
|
||||
groups: Vec<&'a Layer>,
|
||||
number: String,
|
||||
}
|
||||
|
||||
/// The layers of `layers` (one level, bottom first as stored) to write, top to bottom, with
|
||||
/// their groups walked; skips go to `skipped`. `path` is the group part of the number so far.
|
||||
fn plan_layer_exports<'a>(
|
||||
layers: &'a [Layer],
|
||||
groups: &mut Vec<&'a Layer>,
|
||||
path: &str,
|
||||
visible_only: bool,
|
||||
planned: &mut Vec<PlannedLayer<'a>>,
|
||||
skipped: &mut Vec<SkippedExportLayer>,
|
||||
) -> Result<()> {
|
||||
if groups.len() > MAX_GROUP_DEPTH {
|
||||
return Err(EngineError::Other(format!("Layers to Files: groups nested more than {MAX_GROUP_DEPTH} deep")));
|
||||
}
|
||||
let (mut art, mut group) = (0usize, 0usize);
|
||||
for l in layers.iter().rev() {
|
||||
if let Some(children) = l.children() {
|
||||
let number = group;
|
||||
group += 1;
|
||||
if !l.visible && visible_only {
|
||||
skip_hidden_group(children, skipped);
|
||||
continue;
|
||||
}
|
||||
groups.push(l);
|
||||
let r = plan_layer_exports(children, groups, &format!("{path}{number:04}s_"), visible_only, planned, skipped);
|
||||
groups.pop();
|
||||
r?;
|
||||
continue;
|
||||
}
|
||||
// Every layer takes its index, even one skipped as hidden or as an adjustment, so a file
|
||||
// keeps the same number whether Visible Layers Only is on or off (#13959).
|
||||
let number = format!("{path}{art:04}");
|
||||
art += 1;
|
||||
if !l.visible && visible_only {
|
||||
skipped.push(SkippedExportLayer { layer: l.id.0, name: l.name.clone(), reason: "hidden by visibleOnly" });
|
||||
continue;
|
||||
}
|
||||
if matches!(l.content, LayerContent::Adjustment(_)) {
|
||||
skipped.push(SkippedExportLayer { layer: l.id.0, name: l.name.clone(), reason: "adjustment layer has no pixels of its own" });
|
||||
continue;
|
||||
}
|
||||
planned.push(PlannedLayer { l, groups: groups.clone(), number });
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Every layer under a group hidden while Visible Layers Only is on, top to bottom, as skipped.
|
||||
fn skip_hidden_group(layers: &[Layer], skipped: &mut Vec<SkippedExportLayer>) {
|
||||
let mut stack: Vec<&Layer> = layers.iter().collect();
|
||||
while let Some(l) = stack.pop() {
|
||||
match l.children() {
|
||||
Some(children) => stack.extend(children.iter()),
|
||||
None => skipped.push(SkippedExportLayer { layer: l.id.0, name: l.name.clone(), reason: "hidden by visibleOnly" }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Include ICC Profile for one layer file: off, no profile; on, the document's profile, or the one
|
||||
/// its colours are taken to be in when it has none (PSD included), except that a CMYK document's
|
||||
/// PNG (written as RGB) carries none, as measured. Unset changes nothing. Off only leaves the
|
||||
@@ -462,3 +552,7 @@ pub(super) fn push_unique(v: &mut Vec<f64>, x: f64) {
|
||||
#[cfg(test)]
|
||||
#[path = "export_clut_stack_tests.rs"]
|
||||
mod export_clut_stack_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "layers_to_files_groups_tests.rs"]
|
||||
mod layers_to_files_groups_tests;
|
||||
@@ -0,0 +1,184 @@
|
||||
//! #13957: Layers to Files walks groups: every layer in a group gets a file named
|
||||
//! `<prefix>_<group index>s_<index in group>_<name>`, a group gets none, and art layers and groups
|
||||
//! are counted separately at each level.
|
||||
|
||||
use super::*;
|
||||
use photocraft_doc::TextLayer;
|
||||
|
||||
/// The issue's `l2f-test`, top to bottom: `Type` (text), group `Grp` holding `Inner` (red over
|
||||
/// the whole canvas), `Hidden` (hidden), `Blue Half`, `Red`, `Background`.
|
||||
/// The colour `Inner` is painted with.
|
||||
const INNER_RGBA: [f32; 4] = [1.0, 0.0, 0.0, 1.0];
|
||||
|
||||
fn session() -> Session {
|
||||
let mut s = crate::session();
|
||||
s.execute("file.new", json!({"width": 20, "height": 15, "name": "l2f-test"})).unwrap();
|
||||
for name in ["Red", "Blue Half", "Hidden", "Inner"] {
|
||||
s.execute("layer.new.layer", json!({"name": name})).unwrap();
|
||||
if name == "Hidden" {
|
||||
s.execute("layer.setProps", json!({"visible": false})).unwrap();
|
||||
}
|
||||
}
|
||||
s.edit("groups", |doc, _| {
|
||||
let mut inner = doc.layers.pop().unwrap();
|
||||
let LayerContent::Raster(surface) = &mut inner.content else { panic!("Inner is a pixel layer") };
|
||||
let mut px = [0.0f32; 8];
|
||||
let k = photocraft_raster::from_rgba_into(&surface.format(), INNER_RGBA, &mut px);
|
||||
surface.write_region(Rect::new(0, 0, 20, 15), &px[..k].repeat(20 * 15));
|
||||
doc.layers.push(Layer::group("Grp", vec![inner]));
|
||||
doc.layers.push(Layer::new("Type", LayerContent::Text(TextLayer { text: "T".into(), ..Default::default() })));
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
s
|
||||
}
|
||||
|
||||
/// Runs the export with `params` and returns the report and each file's bytes by name.
|
||||
fn export(s: &Session, params: Value) -> (LayerExportReport, Vec<(String, Vec<u8>)>) {
|
||||
let mut written = Vec::new();
|
||||
let report = export_layers_report_with(s, ¶ms, |name, bytes| {
|
||||
written.push((name.to_string(), bytes.to_vec()));
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
(report, written)
|
||||
}
|
||||
|
||||
fn skipped(report: &LayerExportReport) -> Vec<&str> {
|
||||
report.skipped.iter().map(|l| l.name.as_str()).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layers_in_a_group_get_a_file_each_and_the_group_none() {
|
||||
let (report, written) = export(&session(), json!({"format": "psd", "visibleOnly": false}));
|
||||
let expected = [
|
||||
"l2f-test_0000_Type.psd",
|
||||
"l2f-test_0000s_0000_Inner.psd",
|
||||
"l2f-test_0001_Hidden.psd",
|
||||
"l2f-test_0002_Blue Half.psd",
|
||||
"l2f-test_0003_Red.psd",
|
||||
"l2f-test_0004_Background.psd",
|
||||
];
|
||||
assert_eq!(report.files, expected);
|
||||
assert_eq!(written.iter().map(|(n, _)| n.as_str()).collect::<Vec<_>>(), expected);
|
||||
assert!(report.skipped.is_empty());
|
||||
// Inner's PSD keeps it inside Grp (Pass Through), with nothing else in the file.
|
||||
let (_, inner) = &written[1];
|
||||
let doc = photocraft_io::import("x.psd", inner).unwrap().document;
|
||||
assert_eq!(doc.layers.len(), 1, "{:?}", doc.layers.iter().map(|l| &l.name).collect::<Vec<_>>());
|
||||
let grp = &doc.layers[0];
|
||||
assert_eq!(grp.name, "Grp");
|
||||
assert_eq!(grp.blend, photocraft_doc::BlendMode::PassThrough);
|
||||
let children: Vec<&str> = grp.children().unwrap().iter().map(|l| l.name.as_str()).collect();
|
||||
assert_eq!(children, ["Inner"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nested_groups_repeat_the_pattern_and_count_per_level() {
|
||||
let mut s = session();
|
||||
// Inside Grp, above Inner: `Deep` holding `Leaf`, then a second top-level group `Second`
|
||||
// holding `Other`, above Type.
|
||||
s.edit("nest", |doc, _| {
|
||||
let leaf = Layer::new("Leaf", LayerContent::Text(TextLayer { text: "L".into(), ..Default::default() }));
|
||||
let other = Layer::new("Other", LayerContent::Text(TextLayer { text: "O".into(), ..Default::default() }));
|
||||
let grp = doc.layers.iter_mut().find(|l| l.name == "Grp").unwrap();
|
||||
grp.children_mut().unwrap().push(Layer::group("Deep", vec![leaf]));
|
||||
doc.layers.push(Layer::group("Second", vec![other]));
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let (report, _) = export(&s, json!({"visibleOnly": false}));
|
||||
assert_eq!(
|
||||
report.files,
|
||||
[
|
||||
"l2f-test_0000s_0000_Other.png",
|
||||
"l2f-test_0000_Type.png",
|
||||
"l2f-test_0001s_0000s_0000_Leaf.png",
|
||||
"l2f-test_0001s_0000_Inner.png",
|
||||
"l2f-test_0001_Hidden.png",
|
||||
"l2f-test_0002_Blue-Half.png",
|
||||
"l2f-test_0003_Red.png",
|
||||
"l2f-test_0004_Background.png",
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_hidden_groups_layers_follow_visible_layers_only() {
|
||||
let mut s = session();
|
||||
s.edit("hide Grp", |doc, _| {
|
||||
doc.layers.iter_mut().find(|l| l.name == "Grp").unwrap().visible = false;
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let (report, written) = export(&s, json!({"visibleOnly": false}));
|
||||
assert!(report.files.contains(&"l2f-test_0000s_0000_Inner.png".to_string()), "{:?}", report.files);
|
||||
// Its file shows Inner although Grp is hidden in the document.
|
||||
let (_, inner) = written.iter().find(|(n, _)| n.contains("Inner")).unwrap();
|
||||
let doc = photocraft_io::import("x.png", inner).unwrap().document;
|
||||
assert_eq!((doc.size.width, doc.size.height), (20, 15));
|
||||
let red = |p: &[f32; 4]| p.iter().zip(INNER_RGBA).all(|(a, b)| (a - b).abs() < 0.01);
|
||||
assert!(photocraft_compose::flatten(&doc).px.iter().any(red), "the Inner file shows Inner's red pixels");
|
||||
let (report, _) = export(&s, json!({"visibleOnly": true}));
|
||||
assert_eq!(report.files, ["l2f-test_0000_Type.png", "l2f-test_0002_Blue-Half.png", "l2f-test_0003_Red.png", "l2f-test_0004_Background.png"]);
|
||||
assert_eq!(skipped(&report), ["Inner", "Hidden"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_and_deep_groups_never_panic() {
|
||||
let mut s = session();
|
||||
s.edit("empty and deep", |doc, _| {
|
||||
doc.layers.push(Layer::group("Empty", Vec::new()));
|
||||
let mut deep = Layer::new("Bottom", LayerContent::Text(TextLayer { text: "B".into(), ..Default::default() }));
|
||||
for i in 0..200 {
|
||||
deep = Layer::group(format!("G{i}"), vec![deep]);
|
||||
}
|
||||
doc.layers.push(deep);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let e = export_layers_report_with(&s, &json!({"visibleOnly": false}), |_, _| Ok(())).unwrap_err();
|
||||
assert!(e.to_string().contains("nested more than"), "{e}");
|
||||
let mut s = session();
|
||||
s.edit("empty", |doc, _| {
|
||||
doc.layers.push(Layer::group("Empty", Vec::new()));
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let (report, _) = export(&s, json!({"visibleOnly": false}));
|
||||
// The empty group still takes group number 0000, so Grp is 0001s.
|
||||
assert_eq!(report.files[1], "l2f-test_0001s_0000_Inner.png");
|
||||
}
|
||||
|
||||
/// CodeRabbit on #15201: a layer inside 42 groups gets a 264 byte file name (6 bytes per group level),
|
||||
/// which common file systems refuse. The export fails with a clear error before any file is written;
|
||||
/// 40 groups (252 bytes) still export.
|
||||
#[test]
|
||||
fn a_file_name_longer_than_255_bytes_is_refused_before_anything_is_written() {
|
||||
let nested = |groups: usize| {
|
||||
let mut s = crate::session();
|
||||
s.execute("file.new", json!({"width": 4, "height": 4})).unwrap();
|
||||
s.edit("nested", |doc, _| {
|
||||
doc.layers.clear();
|
||||
let mut deep = Layer::new("L", LayerContent::Text(TextLayer { text: "L".into(), ..Default::default() }));
|
||||
for i in 0..groups {
|
||||
deep = Layer::group(format!("G{i}"), vec![deep]);
|
||||
}
|
||||
doc.layers.push(Layer::new("Top", LayerContent::Text(TextLayer { text: "T".into(), ..Default::default() })));
|
||||
doc.layers.push(deep);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
s
|
||||
};
|
||||
let mut written = Vec::new();
|
||||
let e = export_layers_report_with(&nested(42), &json!({"prefix": "d", "visibleOnly": false}), |name, _| {
|
||||
written.push(name.to_string());
|
||||
Ok(())
|
||||
})
|
||||
.unwrap_err();
|
||||
assert!(e.to_string().contains("264 bytes") && e.to_string().contains("255"), "{e}");
|
||||
assert!(written.is_empty(), "nothing written before the refusal: {written:?}");
|
||||
let (report, _) = export(&nested(40), json!({"prefix": "d", "visibleOnly": false}));
|
||||
assert_eq!(report.files.iter().map(String::len).max(), Some(252), "40 groups: 252 bytes, accepted");
|
||||
}
|
||||
@@ -2778,7 +2778,7 @@ fn layers_to_files_reports_skipped_layers_without_changing_files() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layers_to_files_reports_groups_as_exports_and_failures_as_errors() {
|
||||
fn layers_to_files_walks_groups_and_reports_failures_as_errors() {
|
||||
let mut s = session(4, 4, 8);
|
||||
s.execute("layer.newAdjustmentLayer.levels", json!({})).unwrap();
|
||||
s.execute("layer.new.groupFromLayers", json!({"name": "Pack"})).unwrap();
|
||||
@@ -2790,9 +2790,10 @@ fn layers_to_files_reports_groups_as_exports_and_failures_as_errors() {
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(names, vec!["doc_0000_Pack.png", "doc_0001_Background.png"]);
|
||||
// Groups are walked (#13957): Pack gets no file, and its adjustment layer is skipped.
|
||||
assert_eq!(names, vec!["doc_0000_Background.png"]);
|
||||
assert_eq!(report.files, names);
|
||||
assert!(report.skipped.is_empty(), "a group's adjustment is not an omitted top-level layer");
|
||||
assert_eq!(report.skipped.iter().map(|l| l.reason).collect::<Vec<_>>(), ["adjustment layer has no pixels of its own"]);
|
||||
assert_eq!(export_layers_with(&s, ¶ms, |_, _| Ok(())).unwrap(), names, "legacy Rust helper remains compatible");
|
||||
assert!(export_layers_report_with(&s, ¶ms, |_, _| Err(EngineError::Other("disk full".into()))).unwrap_err().to_string().contains("disk full"));
|
||||
assert!(export_layers_report_with(&s, &json!({"format": "not-a-format"}), |_, _| panic!("must not write")).is_err());
|
||||
|
||||
@@ -559,7 +559,7 @@ stdio, and a value that is not a port is a usage error naming the variable. Impl
|
||||
| `doc.open` / `doc.new` | `{path, approveHighMemory? (false)}` / `file.new` params (`approveHighMemory` is the same one-shot PSD/PSB consent as the `file.openAs` command; see [development.md](development.md) for the structured refusal fields) |
|
||||
| `doc.place` | `{path, scale? (percent), fit? (true), center? ([x, y]), approveHighMemory? (false), index?}`: places a file as a Smart Object layer above the active one and returns `{layer, scale, bounds}`. `path` resolves beneath the read root, so this is the capability-scoped `file.placeEmbedded` — that command itself still refuses an ambient path. `approveHighMemory` is refused unless it is a boolean |
|
||||
| `doc.replaceSmartObject` | `{path, layer? (id or name; default the active layer), index?}` → the command's `{layer, instances}`: replaces a Smart Object's contents (one history step, transform and filters kept). `path` resolves beneath the read root, so this is the capability-scoped `layer.smartObjects.replaceContents`, which itself still refuses an ambient path (#8061) |
|
||||
| `doc.exportLayers` | `{dir, format? (png), prefix?, visibleOnly? (true), quality?, index?}` → `{files, skipped}` (plus `count` for workspace exports): one file per exported top-level layer, named like `file.export.layersToFiles` names them. `count` is present only for workspace exports and counts written files only. `skipped` is always an array (empty when nothing is omitted), in top-to-bottom order, of `{layer, name, reason}`: the session layer id, original unsanitized name, and `"hidden by visibleOnly"` or `"adjustment layer has no pixels of its own"`. Visibility takes precedence for hidden adjustments; `visibleOnly:false` exports hidden non-adjustment layers. Groups export merged; their children are not separate exports or skips. Existing filenames/numbering are unchanged. `dir` resolves beneath the write root, so the ambient command stays refused. The bytes come from the command's own core, so both paths write the same files; the write capability refuses to overwrite an existing file. Encode/write failures are errors, not skips |
|
||||
| `doc.exportLayers` | `{dir, format? (png), prefix?, visibleOnly? (true), quality?, index?}` → `{files, skipped}` (plus `count` for workspace exports): one file per exported layer, named like `file.export.layersToFiles` names them: `<prefix>_<index>_<name>` at the top level and `<prefix>_<group index>s_<index>_<name>` inside a group (one `<index>s_` per group level), art layers and groups counted separately at each level. `count` is present only for workspace exports and counts written files only. `skipped` is always an array (empty when nothing is omitted), in top-to-bottom order, of `{layer, name, reason}`: the session layer id, original unsanitized name, and `"hidden by visibleOnly"` or `"adjustment layer has no pixels of its own"`. Visibility takes precedence for hidden adjustments; `visibleOnly:false` exports hidden non-adjustment layers. Groups are walked: a group gets no file, each layer in it does (inside its groups in the file), and with `visibleOnly` the layers of a hidden group are skipped as `"hidden by visibleOnly"`. `dir` resolves beneath the write root, so the ambient command stays refused. The bytes come from the command's own core, so both paths write the same files; the write capability refuses to overwrite an existing file. Encode/write failures are errors, not skips |
|
||||
| `doc.exportDataSets` | `{dir, format? (png), dataSets? (all), naming? ("{name}\|{index}\|{document}"), index?}` → `{files, count}`: the capability-scoped `file.export.dataSetsAsFiles`. The batch is planned first and colliding names are refused before any file is written, as in the command |
|
||||
| `doc.importDataSets` | `{path, delimiter? (,), index?}` → `{imported}`: the capability-scoped `file.import.variableDataSets`; the CSV is read beneath the read root |
|
||||
| `doc.save` | `{path?, format?, quality?, index?, tiffLayers?, tiffCompression?, tiffTransparency?, tiffPyramid?, tgaBits?, dpxBits?, ddsCompression?, ddsMipmaps?, pdfSpotPlates?, pcraftFullComposite?, maximizeCompatibility?}` (`.pcraft` native, else export by extension; set `tiffLayers: true` to preserve TIFF layers rather than exporting a flattened TIFF; `tiffCompression` (`none`, `lzw`, `zip`), `tiffTransparency` (bool: Save Transparency; unset, kept unless the document has alpha or spot channels) and `tiffPyramid` (bool) are TIFF Options; `dpxBits` selects 8, 10, 12 or 16 bits per sample for DPX (unset: 8 for an 8-bit document, otherwise 16); `tgaBits` 24 or 32 sets a TGA's bits per pixel, `ddsCompression`/`ddsMipmaps` a DDS texture's compression and mip chain, and `maximizeCompatibility: false` writes a layered PSD/PSB with Photoshop's placeholder instead of the merged image, except for Bitmap, Indexed Color and Duotone documents, as `app.save` does; `pdfSpotPlates: false` leaves a PDF's spot plates out, which are written by default, and refuses a Multichannel document, which has no image to write without them; `pcraftFullComposite: true` also writes the flattened document at its canvas size into a `.pcraft` file as `composite/full.png`; the save may leave it out in the cases listed in [the format guide](../book/src/formats/pcraft.md), and the manifest's `full_composite` member names it when written). Without `path` only a PSD, PSB or `.pcraft` document is written back to its own file, in its own format; anything else is an error and the file is left unchanged. A successful layered save (PSD, PSB or `.pcraft`) records the current revision as saved and makes the file the document's path, so `session.list` reports `dirty: false`; a flat export is a copy and leaves the document dirty |
|
||||
|
||||
Reference in new issue
Block a user