feat(array): ARRAYRECT and ARRAYPOLAR create associative arrays

With the new Associative option on (the default), ARRAYRECT and
ARRAYPOLAR build the array the way the drawing format stores one: the
selected objects move into an anonymous source block, an anonymous
array block holds one ByBlock reference to it per item, an INSERT of
the array block takes their place, and an AcDbAssocAction with an
AcDbAssocArrayActionBody, its three dependencies, the BaseNormal /
Origin / basePoint parameters and the value parameters tie them
together in the model-space network. The array is then edited from
Properties like an array read from a file.

The option flips with AS and is remembered for the session; on a
rotated working plane the commands keep making plain copies. Saving
drops the action of an array whose reference was erased or exploded.

Checked: created arrays reopen as associative with their parameters
and items, and the ODA converter reads the saved DWG without errors.

Refs #1109

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hakan SevenandClaude Opus 5.5 committed 2026-10-13 21:23:48 +03:00
1 parent 2bf77e4bd6
commit f0ac89629b
30 files changed
+705 -3

No files matched your search

+40
View File
@@ -66,6 +66,46 @@ impl OpenCADStudio {
None
}
/// ARRAYRECT / ARRAYPOLAR with Associative on: the objects become the
/// source of an associative array, in one undo step.
pub(super) fn handle_assoc_array(
&mut self,
mut handles: Vec<Handle>,
spec: crate::scene::assoc_array::AssocArraySpec,
) {
let i = self.active_tab;
handles.retain(|handle| !self.tabs[i].scene.is_layer_locked(*handle));
self.tabs[i].scene.clear_preview_wire();
self.tabs[i].active_cmd = None;
self.tabs[i].snap_result = None;
self.restore_pre_cmd_tangent();
if handles.is_empty() {
return;
}
let label = self.history_label_from_active_cmd(i, "ARRAY");
let source_point = crate::app::helpers::entities_lower_left_by_bbox(
&self.tabs[i].scene.document,
&handles,
);
self.push_undo_snapshot(i, label.clone());
match crate::scene::assoc_array::create_from_spec(
&mut self.tabs[i].scene,
&handles,
source_point,
&spec,
) {
Ok(array) => {
self.tabs[i].scene.deselect_all();
self.tabs[i].scene.select_entity(array, false);
self.command_line
.push_output(crate::tf!("{label}: associative array created.").as_ref());
}
Err(error) => self.command_line.push_error(&format!("{label}: {error}")),
}
self.tabs[i].dirty = true;
self.refresh_properties();
}
pub(super) fn handle_replace_many(
&mut self,
replacements: Vec<(Handle, Vec<codec::EntityType>)>,
+3
View File
@@ -606,6 +606,9 @@ impl OpenCADStudio {
return task;
}
}
CmdResult::AssocArray { handles, spec } => {
self.handle_assoc_array(handles, spec);
}
CmdResult::ReplaceMany(replacements, additions) => {
if let Some(task) = self.handle_replace_many(replacements, additions) {
return task;