using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; using Autodesk.ProcessPower.PlantInstance; using Autodesk.Windows; using AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application; namespace PRecAnnot.Plant3D2026; public sealed class EntryPoint : IExtensionApplication { public void Initialize() => RibbonIntegration.Register(); public void Terminate() { } [CommandMethod("PHP_REC_ANNOT")] public void PrimaryCommand() => RunDiagnostic("PHP_REC_ANNOT"); [CommandMethod("PXP-AAV")] public void AutoAnnotateViewCommand() => RunDiagnostic("PXP-AAV"); [CommandMethod("PXP-OA")] public void OrthoAnnotateCommand() => RunDiagnostic("PXP-OA"); private static void RunDiagnostic(string commandName) { try { Document? document = AcadApplication.DocumentManager.MdiActiveDocument; if (document is null) return; Editor editor = document.Editor; if (PlantApplication.CurrentProject is null) { editor.WriteMessage("\nP_Rec_Annot: активный Plant 3D project не найден; DWG не изменён."); return; } editor.WriteMessage($"\nP_Rec_Annot {commandName}: Plant 3D project '{PlantApplication.CurrentProject.Name}' найден; diagnostic-only, DWG не изменён."); } catch (System.Exception exception) { try { AcadApplication.DocumentManager.MdiActiveDocument?.Editor.WriteMessage($"\nP_Rec_Annot: безопасная диагностика завершилась ошибкой: {exception.Message}"); } catch { } } } } internal static class RibbonIntegration { private const string TabId = "PRecAnnot.Plant3D2026"; private const string Command = "PHP_REC_ANNOT "; public static void Register() { try { RibbonControl? ribbon = ComponentManager.Ribbon; if (ribbon is null) return; RibbonTab? tab = ribbon.Tabs.FirstOrDefault(item => string.Equals(item.Id, TabId, StringComparison.OrdinalIgnoreCase)); if (tab is null) { tab = new RibbonTab { Id = TabId, Title = "Промхимпроект" }; ribbon.Tabs.Add(tab); } if (tab.Panels.Any(panel => string.Equals(panel.Source?.Title, "Аннотации", StringComparison.OrdinalIgnoreCase))) return; RibbonPanelSource source = new() { Title = "Аннотации" }; source.Items.Add(new RibbonButton { Text = "Аннотировать", ShowText = true, CommandParameter = Command }); tab.Panels.Add(new RibbonPanel { Source = source }); } catch { // Ribbon is optional; command-line registration remains available. } } }