// Copyright 🄫 2023 Elekta K.K. using Elekta.MonacoScripting.API; using Elekta.MonacoScripting.API.General; using Elekta.MonacoScripting.DataType; using Elekta.MonacoScripting.Log; using System; using System.Collections.Generic; using System.Configuration; using System.Windows.Forms; namespace SegmentsSpreadsheetSample { internal class Program { /* This is stating the variables to be used in this script. * These variables need to be added in App.config file before being used here. * * This is an example of how the variables can be used in a script. * You can change/add/delete variables in your own scirpt. * You can also use other approaches to use variables in your script. */ // Aquire settings from App.config. [STAThread] static void Main(string[] args) { try { // Optional: invoke DeactivateExitErrorHandler to deactivate terminating this application when any error information is logged. Logger.Instance.DeactivateExitErrorHandler(); // Optional: invoke ActivateScreenShot to activate screenshot capture when any error information is logged. Logger.Instance.DeactivateScreenShot(); // Monaco application instance. MonacoApplication app = MonacoApplication.Instance; // Get current patient. var pat = app.GetCurrentPatient(); // Get active plan. var plan = app.GetActivePlan(); // Ouput information Logger.Instance.Info("+---------+------------------------+"); Logger.Instance.Info($"|Clinic |{pat.Clinic,-24}|"); Logger.Instance.Info("+---------+------------------------+"); Logger.Instance.Info($"|PatientID|{pat.Id,-24}|"); Logger.Instance.Info("+---------+------------------------+"); Logger.Instance.Info($"|Name |{pat.Name,-24}|"); Logger.Instance.Info("+---------+------------------------+"); Logger.Instance.Info($"|PlanID |{plan,-24}|"); Logger.Instance.Info("+---------+------------------------+"); // Get segments spreadsheet. var segmentsData = app.GetSegmentsSpreadsheet().GetAllBeamSegments(); foreach (var beam in segmentsData.SegmentsOfAllBeams) { Logger.Instance.Info("+-------------------------------------------------------------------------------------------------+"); Logger.Instance.Info($"|Beam #{beam.Key, -4} |"); Logger.Instance.Info("+-------+-----+-----+-------+-----------------+------------+------------+------------+------------+"); Logger.Instance.Info($"|{"Segment", 7}|{"%", 5}|{"Lock", -5}|{"MU / Fx", 7}|{"Segment Area(cm2)", 17}|{"Width1(cm)", 12}|{"Width2(cm)", 12}|{"Length1(cm)", 12}|{"Length2(cm)", 12}|"); Logger.Instance.Info("+-------+-----+-----+-------+-----------------+------------+------------+------------+------------+"); foreach (var seg in beam.Value) { Logger.Instance.Info($"|{seg.Segment, 7}|{seg.Weight, 5:F2}|{seg.Lock, -5}|{seg.MuFx, 7:F2}|{seg.SegmentArea, 17:F3}|{seg.Width1, 12:F2}|{seg.Width2, 12:F2}|{seg.Length1, 12:F2}|{seg.Length2, 12:F2}|"); } Logger.Instance.Info("+-------+-----+-----+-------+-----------------+------------+------------+------------+------------+"); } // Indicate user when the job is done. Logger.Instance.Info("Done."); } catch (Exception ex) { // Display an error dialog if any exception is catched during script execution MessageBox.Show(ex.Message, "Exception occurred", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } } } }