diff --git a/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Plant3D2026/EntryPoint.cs b/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Plant3D2026/EntryPoint.cs index 460e67a..9caa8ec 100644 --- a/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Plant3D2026/EntryPoint.cs +++ b/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Plant3D2026/EntryPoint.cs @@ -57,7 +57,7 @@ public sealed class EntryPoint : IExtensionApplication [CommandMethod("PXP-IOD", CommandFlags.Session)] public void UpdateOrthoDrawingsCommand() => PRecAnnot.Plant3D2026.UpdateOrthoDrawingsCommand.Run(); [CommandMethod("mto-ma")] public void ShowManualAnnotationPaletteCommand() => ManualAnnotationPalette.Show(); [CommandMethod("PXP-MA")] public void ShowManualAnnotationPaletteAliasCommand() => ManualAnnotationPalette.Show(); - [CommandMethod("CAC1")] public void PlaceManualAnnotationCommand() => ManualAnnotationPalette.PlaceSelected(); + [CommandMethod("CAC1")] public void PlaceManualAnnotationCommand() => ManualAnnotationEditCommand.Run(); [CommandMethod("PXP-MAB")] public void InsertManualBlockCommand() => ManualBlockInsertionCommand.Run(ManualAnnotationPalette.CurrentState()); [CommandMethod("PHP_REC_AUTOMATION_START", CommandFlags.Session)] diff --git a/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Plant3D2026/ManualAnnotationEditCommand.cs b/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Plant3D2026/ManualAnnotationEditCommand.cs new file mode 100644 index 0000000..90d5739 --- /dev/null +++ b/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Plant3D2026/ManualAnnotationEditCommand.cs @@ -0,0 +1,56 @@ +using Autodesk.AutoCAD.DatabaseServices; +using Autodesk.AutoCAD.EditorInput; +using Autodesk.AutoCAD.ApplicationServices; +using PRecAnnot.Core; +using AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application; + +namespace PRecAnnot.Plant3D2026; + +internal static class ManualAnnotationEditCommand +{ + private const string AppName = "P_REC_ANNOT_MANUAL"; + + public static void Run() + { + var document = AcadApplication.DocumentManager.MdiActiveDocument; + if (document is null) return; + var options = new PromptEntityOptions("\nSelect owned manual annotation to edit: "); + options.SetRejectMessage("\nSelect a block reference."); + options.AddAllowedClass(typeof(BlockReference), true); + var selection = document.Editor.GetEntity(options); + if (selection.Status != PromptStatus.OK) return; + + using var documentLock = document.LockDocument(); + using var transaction = document.Database.TransactionManager.StartTransaction(); + var reference = transaction.GetObject(selection.ObjectId, OpenMode.ForWrite) as BlockReference; + if (reference is null) return; + var state = ReadState(reference); + if (state is null) + { + document.Editor.WriteMessage("\nManual annotation state is missing or invalid; no migration was performed."); + return; + } + + document.Editor.WriteMessage($"\nRestored {state.Kind}; datum={state.DatumMode}; offset={state.DatumOffset:0.###}."); + foreach (ObjectId attributeId in reference.AttributeCollection) + { + var attribute = transaction.GetObject(attributeId, OpenMode.ForWrite) as AttributeReference; + if (attribute is null) continue; + var prompt = new PromptStringOptions($"\n{attribute.Tag} <{attribute.TextString}>: ") { AllowSpaces = true, UseDefaultValue = true, DefaultValue = attribute.TextString }; + var value = document.Editor.GetString(prompt); + if (value.Status == PromptStatus.OK) attribute.TextString = value.StringResult; + else if (value.Status is PromptStatus.Cancel or PromptStatus.Error) return; + } + reference.XData = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataRegAppName, AppName), new TypedValue((int)DxfCode.ExtendedDataAsciiString, state.Serialize())); + transaction.Commit(); + document.Editor.WriteMessage("\nManual annotation updated; native AutoCAD UNDO is available."); + RuntimeDiagnostics.Write("ManualAnnotationEditCompleted", commandName: "CAC1", resultStatus: "Updated", document: document); + } + + private static ManualAnnotationState? ReadState(BlockReference reference) + { + using var data = reference.GetXDataForApplication(AppName); + var serialized = data?.AsArray().FirstOrDefault(value => value.TypeCode == (int)DxfCode.ExtendedDataAsciiString).Value as string; + return ManualAnnotationState.Deserialize(serialized); + } +}