Image Trace: tracing again keeps the tracing's note and tags

Tracing an Image Trace object again, with Image Trace > Make, Make and
Expand, or a script's tracing options, replaced the object with one
that had no attributes, so its note, tags and URL were lost. The new
object now takes them over. A script's saved Tags and Tag objects
follow the new object and keep their identity, as the PluginItem
does.

pathItems.removeAll() and textFrames.removeAll() could leave an image
at the bottom of an ordinary group named Image Trace, which made the
group a tracing. Both now throw "Only Image Trace can make a tracing"
before anything is deleted, as move, remove() and zOrder do,
counting a compound path that the deletion leaves empty.

Follows up #9077.
This commit is contained in:
dotCooCoo committed 2026-12-02 15:46:12 -08:00
1 parent f207334070
commit 1b9f1e26e8
8 files changed
+137 -26

No files matched your search

+14 -11
View File
@@ -1225,17 +1225,20 @@ pub(super) fn trace_make(s: &mut Session, p: &Value, expand: bool) -> Result<Val
let gid = d.alloc_id();
let mut g = Node::group(gid, children);
g.name = if expand { None } else { Some(TRACE_NAME.into()) };
// Tracing again keeps the tracing's own object settings: opacity, blend mode, its
// appearance items, visibility and lock.
if !expand && is_trace_group(&src) {
g.visible = src.visible;
g.locked = src.locked;
g.opacity = src.opacity;
g.blend = src.blend;
g.isolate = src.isolate;
g.knockout = src.knockout;
g.knockout_shape = src.knockout_shape;
g.appearance = src.appearance.clone();
// Tracing again keeps the tracing's note, tags and URL, including when expanding.
// Without expansion, it also keeps the tracing's other object settings.
if is_trace_group(&src) {
g.extras_mut().attrs = src.extras().attrs.clone();
if !expand {
g.visible = src.visible;
g.locked = src.locked;
g.opacity = src.opacity;
g.blend = src.blend;
g.isolate = src.isolate;
g.knockout = src.knockout;
g.knockout_shape = src.knockout_shape;
g.appearance = src.appearance.clone();
}
}
if !expand {
// Tracing again keeps the object's view unless another is asked for, and the Split
+18
View File
@@ -2896,6 +2896,24 @@ fn makes_tracing(d: &Document, parent: NodeId, id: NodeId, at: Option<usize>) ->
}
}
/// Whether deleting the objects `ids` together would leave an image first in an ordinary group
/// named as a tracing, which would make that group one. `edit.clear` also deletes a compound path
/// it leaves empty, so such a compound path counts as deleted.
pub(super) fn clearing_makes_tracing(d: &Document, ids: &[NodeId]) -> bool {
let mut gone: HashSet<NodeId> = ids.iter().copied().collect();
let compounds: HashSet<NodeId> =
ids.iter().filter_map(|i| d.parent_of(*i)).filter(|p| matches!(d.node(*p).map(|n| &n.kind), Some(NodeKind::Compound { .. }))).collect();
for c in compounds {
if d.children(Some(c)).is_some_and(|k| k.iter().all(|n| gone.contains(&n.id))) {
gone.insert(c);
}
}
let parents: HashSet<NodeId> = gone.iter().filter_map(|i| d.parent_of(*i)).filter(|p| !gone.contains(p)).collect();
parents.into_iter().filter(|p| named_as_tracing(d, *p)).any(|p| {
d.children(Some(p)).and_then(|c| c.iter().find(|n| !gone.contains(&n.id)).map(|n| matches!(n.kind, NodeKind::Image(_)))).unwrap_or(false)
})
}
/// Moves the object `id` to `to` with `node.move`, its index worked out once it has left its place.
fn place(h: &Host, doc: Doc, id: NodeId, to: &Destination) -> std::result::Result<(), HostError> {
let index = with_doc(h, doc, |_, st| {
+8 -3
View File
@@ -474,15 +474,17 @@ fn items_index(h: &super::Host, a: &[Data]) -> Answer {
/// `pathItems.removeAll()`: deletes every path of the document in one command. A hidden or locked
/// path, one in a hidden or locked layer or group, or one on a locked artboard stops it before
/// anything is deleted, as `PageItems.removeAll()` does.
/// anything is deleted, as `PageItems.removeAll()` does, and so does an image the deletion would
/// leave first in an ordinary group named as a tracing.
fn items_remove_all(h: &super::Host, a: &[Data]) -> Answer {
let doc = items_doc(h, a)?;
let (ids, refused, on_locked) = with_doc(h, doc, |_, st| {
let (ids, refused, on_locked, tracing) = with_doc(h, doc, |_, st| {
let ids = path_items(h, st)?;
let refused: Vec<u64> = ids.iter().filter(|i| !editable(&st.doc, **i)).map(|i| i.0).take(20).collect();
let locks = st.doc.locked_artboards();
let on_locked: Vec<u64> = ids.iter().filter(|i| locks.holds_id(**i)).map(|i| i.0).take(20).collect();
Ok::<_, HostError>((ids, refused, on_locked))
let tracing = super::clearing_makes_tracing(&st.doc, &ids);
Ok::<_, HostError>((ids, refused, on_locked, tracing))
})?;
if !refused.is_empty() {
let list = refused.iter().map(u64::to_string).collect::<Vec<_>>().join(", ");
@@ -492,6 +494,9 @@ fn items_remove_all(h: &super::Host, a: &[Data]) -> Answer {
let list = on_locked.iter().map(u64::to_string).collect::<Vec<_>>().join(", ");
return Err(HostError::Error(format!("{ON_LOCKED_ARTBOARD}: {list}")));
}
if tracing {
return Err(HostError::Error(super::NOT_A_TRACING.into()));
}
if !ids.is_empty() {
on_doc(h, doc.uid, true, |h| command(h, "edit.clear", &json!({"ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()})))?;
}
+6 -3
View File
@@ -47,10 +47,12 @@ fn owner_of(h: &Host, d: &Data) -> std::result::Result<Owner, HostError> {
}
/// The page item a handle's run, document uid and id (as [`id_parts`] gave it) name, which must
/// still be in its document.
/// still be in its document. A tracing the run traced again is followed to the object that
/// replaced it, which keeps its tags, as its `PluginItem` is.
fn resolve_item(h: &Host, run: f64, uid: f64, high: f64, low: f64) -> std::result::Result<Item, HostError> {
let doc = find_doc(h, run, uid).ok_or_else(|| HostError::Error(STALE_ITEM.into()))?;
let id = id_of(high, low).ok_or_else(|| HostError::Error(STALE_ITEM.into()))?;
let id = super::tracing::follow(h, doc.uid, id);
let alive = with_doc(h, doc, |_, st| st.doc.node(id).is_some_and(|n| typename(n).is_some()));
if !alive {
return Err(HostError::Error(STALE_ITEM.into()));
@@ -111,7 +113,8 @@ fn doc_of_owner(owner: Owner) -> Doc {
}
fn tag_ref(h: &Host, doc: Doc, id: NodeId, tag: u64) -> Data {
let [high, low] = id_parts(id);
// A tracing traced again keeps the id of the first object of its chain, as its `PluginItem` does.
let [high, low] = id_parts(super::tracing::origin(h, doc.uid, id));
let [tag_high, tag_low] = id_parts(NodeId(tag));
host_ref("Tag", &[float(h.run), float(doc.uid), high, low, tag_high, tag_low])
}
@@ -119,7 +122,7 @@ fn tag_ref(h: &Host, doc: Doc, id: NodeId, tag: u64) -> Data {
/// `PageItem.tags`.
pub(super) fn item_tags(h: &Host, a: &[Data]) -> Answer {
let item = item_of(h, arg(a, 0))?;
let [high, low] = id_parts(item.id);
let [high, low] = id_parts(super::tracing::origin(h, item.doc.uid, item.id));
Ok(host_ref("Tags", &[float(h.run), float(item.doc.uid), high, low]))
}
+8 -3
View File
@@ -1363,16 +1363,18 @@ fn frames_path_text(h: &Host, a: &[Data]) -> Answer {
}
/// `removeAll()`: deletes every type object in one command; a hidden or locked one, or one on a
/// locked artboard, stops it first, as `PageItems.removeAll()` does.
/// locked artboard, stops it first, as `PageItems.removeAll()` does, and so does an image the
/// deletion would leave first in an ordinary group named as a tracing.
fn frames_remove_all(h: &Host, a: &[Data]) -> Answer {
let doc = frames_doc(h, a)?;
let (ids, refused, on_locked) = with_doc(h, doc, |_, st| {
let (ids, refused, on_locked, tracing) = with_doc(h, doc, |_, st| {
let ids = frame_ids(h, st)?;
let ok = |id: &NodeId| editable(&st.doc, *id) && st.doc.node(*id).is_some_and(all_editable);
let refused: Vec<u64> = ids.iter().filter(|i| !ok(i)).map(|i| i.0).take(20).collect();
let locks = st.doc.locked_artboards();
let on_locked: Vec<u64> = ids.iter().filter(|i| locks.holds_id(**i)).map(|i| i.0).take(20).collect();
Ok::<_, HostError>((ids, refused, on_locked))
let tracing = super::clearing_makes_tracing(&st.doc, &ids);
Ok::<_, HostError>((ids, refused, on_locked, tracing))
})?;
if !refused.is_empty() {
let list = refused.iter().map(u64::to_string).collect::<Vec<_>>().join(", ");
@@ -1382,6 +1384,9 @@ fn frames_remove_all(h: &Host, a: &[Data]) -> Answer {
let list = on_locked.iter().map(u64::to_string).collect::<Vec<_>>().join(", ");
return Err(HostError::Error(format!("{}: {list}", super::ON_LOCKED_ARTBOARD)));
}
if tracing {
return Err(HostError::Error(super::NOT_A_TRACING.into()));
}
if !ids.is_empty() {
on_doc(h, doc.uid, true, |h| command(h, "edit.clear", &json!({"ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()})))?;
}
@@ -1302,3 +1302,78 @@ fn retraced_plugin_is_the_same_object_as_its_collection_handle() {
assert_eq!(out, vec![json!(true); 5]);
let _ = std::fs::remove_dir_all(base);
}
#[test]
fn retrace_keeps_the_tracing_note_and_tags() {
let base = folder("retrace-attributes");
let (mut s, _) = session(&base, false);
let out = log(
&mut s,
&base,
"var p = app.activeDocument.rasterItems[0].trace(); p.note = 'keep me'; var tags = p.tags, t = tags.add(); t.name = 'job'; t.value = '42';\
p.tracing.tracingOptions.threshold = 90; vc.log(p.note); vc.log(p.tags.length); vc.log(p.tags[0].name + '=' + p.tags[0].value);\
vc.log(tags.length); vc.log(t.value); vc.log(t === p.tags[0]); vc.log(tags === p.tags);",
);
assert_eq!(out, [json!("keep me"), json!(1), json!("job=42"), json!(1), json!("42"), json!(true), json!(true)]);
// Image Trace › Make on the tracing keeps them too.
let id = traces(&s)[0];
let r = s.execute("imageTrace.make", &json!({"id": id.0, "params": {"threshold": 100}})).unwrap();
let id = NodeId(r["id"].as_u64().unwrap());
let d = &s.active().unwrap().doc;
let attrs = d.node(id).and_then(|n| n.extras().attrs.as_deref().cloned()).unwrap_or_default();
assert_eq!(attrs.note, "keep me");
let tags: Vec<(&str, &str)> = attrs.tags.iter().map(|t| (t.name.as_str(), t.value.as_str())).collect();
assert_eq!(tags, [("job", "42")]);
let r = s.execute("imageTrace.makeAndExpand", &json!({"id": id.0})).unwrap();
let id = NodeId(r["id"].as_u64().unwrap());
let d = &s.active().unwrap().doc;
let group = d.node(id).unwrap();
assert!(matches!(group.kind, NodeKind::Group { .. }));
let attrs = group.extras().attrs.as_deref().cloned().unwrap_or_default();
assert_eq!(attrs.note, "keep me");
let tags: Vec<(&str, &str)> = attrs.tags.iter().map(|t| (t.name.as_str(), t.value.as_str())).collect();
assert_eq!(tags, [("job", "42")]);
let _ = std::fs::remove_dir_all(base);
}
/// `pathItems.removeAll()` and `textFrames.removeAll()` refuse to leave an image at the bottom of an
/// ordinary group named as a tracing, before the document changes.
#[test]
fn remove_all_cannot_leave_an_image_first_in_a_group_named_as_a_tracing() {
let setup = |bottom: &str| {
format!(
"var d = app.activeDocument; d.selection = [{bottom}]; vc.run('object.group');\
var g = d.pageItems[0]; g.name = 'Image Trace'; d.rasterItems[0].move(g, ElementPlacement.PLACEATBEGINNING);"
)
};
for (name, bottom, list) in [
("remove-all-trace-name-paths", "d.pathItems.rectangle(10, 10, 20, 20)", "pathItems"),
// `edit.clear` also deletes the compound path its members leave empty.
(
"remove-all-trace-name-compound",
"(function () { d.selection = [d.pathItems.rectangle(10, 10, 20, 20), d.pathItems.rectangle(40, 40, 5, 5)];\
vc.run('object.compoundPath.make'); return d.pageItems[0]; })()",
"pathItems",
),
("remove-all-trace-name-type", "d.textFrames.pointText([10, 10])", "textFrames"),
] {
let base = folder(name);
let (mut s, _) = session(&base, false);
log(&mut s, &base, &setup(bottom));
let before = vectorcraft_format::save(&s.active().unwrap().doc, false);
let steps = undo_steps(&s);
let out = log(
&mut s,
&base,
&format!(
"var d = app.activeDocument, m = ''; try {{ d.{list}.removeAll(); }} catch (e) {{ m = e.message; }}\
vc.log(m); vc.log(d.pageItems[0].typename);"
),
);
assert_eq!(out, [json!("Only Image Trace can make a tracing"), json!("GroupItem")], "{list}");
assert!(traces(&s).is_empty(), "{list}");
assert_eq!(vectorcraft_format::save(&s.active().unwrap().doc, false), before, "{list}");
assert_eq!(undo_steps(&s), steps, "{list}");
let _ = std::fs::remove_dir_all(base);
}
}
+7 -5
View File
@@ -3143,8 +3143,9 @@ through `$`:
unlocked source image (`TracingObject.sourceArt`) out of its tracing throws `a tracing's source image cannot leave
its tracing` and changes nothing; a hidden source image (the default) throws `Cannot move`. Moving or duplicating
an image to the bottom of an ordinary group named `Image Trace` throws `Only Image Trace can make a tracing` before
the document changes, as renaming such a group does. `move`, `remove()` and `zOrder` throw the same error, with
nothing changed, when they would leave an image at the bottom of such a group. An object of
the document changes, as renaming such a group does. `move`, `remove()`, `zOrder`, `pathItems.removeAll()` and
`textFrames.removeAll()` throw the same error, with nothing changed, when they would leave an image at the bottom of
such a group. An object of
another document throws `Cross-document placement is not available`, and when
`node.move` refuses the place of a copy, `duplicate` throws that error and leaves the documents, the selection and
the undo history as they were before the call. `move` on an object that is hidden or locked, inside a hidden or
@@ -3361,9 +3362,10 @@ through `$`:
count the seam fills of an Abutting trace, `usedColorCount` counts the different fill and stroke paints, and
`imageResolution` is the image's pixels per inch as placed, an error for an image placed at different resolutions
across and down. Assigning an option, or `loadFromPreset(name)`, traces again with `imageTrace.make`, keeps the
source image and the view, and a value the tracing already has runs no command. Assigning `viewRaster` or
`viewVector` does not trace again: it runs `imageTrace.setView`. The `PluginItem`, `TracingObject`
and `TracingOptions` follow the new object, and a run traces again at most 10,000 times. Tracing again throws
source image, the view, and the tracing's attributes (its note, tags and URL), and a value the tracing already has
runs no command. Assigning `viewRaster` or `viewVector` does not trace again: it runs `imageTrace.setView`. The
`PluginItem`, `TracingObject`, `TracingOptions` and the tracing's `Tags` and `Tag` objects follow the new object,
and a run traces again at most 10,000 times. Tracing again throws
`Cannot retrace a tracing containing added artwork`, with nothing changed, when the tracing holds an object its trace
did not make, whether this run, an earlier run or a command added it, and `releaseTracing()` throws
`Cannot release a tracing containing added artwork` in the same case. When no object was added, both throw
+1 -1
View File
@@ -1115,7 +1115,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- The control server writes each reply through a 64 KiB buffer. On Windows 11 it sends the 17 MB `document.inspect` reply of a document with 50,000 objects on one layer to a client over loopback in 0.09 s instead of 34 s.
- Scripts: File › Scripts › Other Script… and `script.run` run a JavaScript file against the open documents as one transaction with one undo step for each changed document. A failed or stopped run puts every document back. `crates/engine/src/tests/script_run.rs`.
- Scripts: `Document.placedItems` and `Document.rasterItems` list a document's linked and embedded images; `placedItems.add()` with a `File` assigned to `file` places an image linked, and `PlacedItem.relink(file)` and `embed()` relink and embed it, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/PlacedItems/, https://ai-scripting.docsforadobe.dev/jsobjref/PlacedItem/, https://ai-scripting.docsforadobe.dev/jsobjref/RasterItems/ and https://ai-scripting.docsforadobe.dev/jsobjref/RasterItem/ describe them. A raster item's bits per channel, channels, color space and transparency come from its encoded pixels' header. Only files the script may read, of at most 256 MiB and holding an image, are placed or relinked. Rasterizing and capturing are not there yet. `crates/engine/src/tests/script_dom_images.rs`.
- Scripts: `PlacedItem.trace()` and `RasterItem.trace()` make an Image Trace object and return it as a `PluginItem` whose `tracing` gives its path, anchor and color counts, the source image's resolution, `expandTracing()`, `releaseTracing()` and its `TracingOptions`; assigning an option or loading a preset traces it again, except that the view options (`viewRaster` and `viewVector`) only change the view, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/PluginItem/, https://ai-scripting.docsforadobe.dev/jsobjref/TracingObject/ and https://ai-scripting.docsforadobe.dev/jsobjref/TracingOptions/ describe them. Option values are checked for type and range before any trace, a script cannot save a preset, and the options without a VectorCraft setting throw. The source image of a traced item is left out of `pageItems`, `placedItems` and `rasterItems`; a script reaches it through `PluginItem.tracing.sourceArt`. Renaming an ordinary group that holds an image first to `Image Trace`, or moving or duplicating an image to the bottom of an ordinary group with that name, throws an error. `crates/engine/src/tests/script_dom_tracing.rs`.
- Scripts: `PlacedItem.trace()` and `RasterItem.trace()` make an Image Trace object and return it as a `PluginItem` whose `tracing` gives its path, anchor and color counts, the source image's resolution, `expandTracing()`, `releaseTracing()` and its `TracingOptions`; assigning an option or loading a preset traces it again, except that the view options (`viewRaster` and `viewVector`) only change the view, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/PluginItem/, https://ai-scripting.docsforadobe.dev/jsobjref/TracingObject/ and https://ai-scripting.docsforadobe.dev/jsobjref/TracingOptions/ describe them. Tracing again keeps the tracing's note, tags and URL. Option values are checked for type and range before any trace, a script cannot save a preset, and the options without a VectorCraft setting throw. The source image of a traced item is left out of `pageItems`, `placedItems` and `rasterItems`; a script reaches it through `PluginItem.tracing.sourceArt`. Renaming an ordinary group that holds an image first to `Image Trace`, or moving or duplicating an image to the bottom of an ordinary group with that name, or deleting paths or type with `removeAll()` so that an image is left at its bottom, throws an error. `crates/engine/src/tests/script_dom_tracing.rs`.
- Scripts: `Document.pathItems` lists the paths and makes rectangles, rounded rectangles, ellipses, polygons, stars and empty paths with the defaults the help page https://ai-scripting.docsforadobe.dev/jsobjref/PathItems/ gives; each path's points, closed state, fill rule, area, length, guide state, selected points, fill and stroke colors, stroke options and transforms read and change as https://ai-scripting.docsforadobe.dev/jsobjref/PathItem/, https://ai-scripting.docsforadobe.dev/jsobjref/PathPoints/ and https://ai-scripting.docsforadobe.dev/jsobjref/PathPoint/ describe them, and `RGBColor`, `CMYKColor`, `GrayColor`, `LabColor` and `NoColor` make colors (`docs/mcp.md`). `pathItems["name"]` reads a path by name as `pageItems` does, and `removeAll()` deletes nothing and throws when any path is on a locked artboard. The transforms move gradients with the art: `changeFillGradients` false throws an error, as do `changeFillPatterns` and `changeStrokePattern` given as different values, and `transform` is not there yet (`docs/mcp.md` lists these limits). Gradient stops are not there yet. A `PathPoint` of a path in an Objects on Path group goes stale when an edit of another path in the group moves it. `crates/engine/src/tests/script_dom_paths.rs`.
- Scripts: a document's `default*` members (https://ai-scripting.docsforadobe.dev/jsobjref/Document/) read and set the fill, stroke and stroke options of the next object drawn through `appearance.setNewArt`, leaving the selection and its art as they were, and `scaleFactor` reads 1 (`docs/mcp.md`). `crates/engine/src/tests/script_dom_defaults.rs`.
- Scripts: `app.undo()` and `app.redo()` undo and redo the edits the run made, and each document open before and after the run that it changed gets one undo step. `crates/engine/src/tests/script_dom.rs`.