// 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 BeamsSpreadsheetSample { 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 beam spreadsheet. var sheet = app.GetBeamsSpreadsheet(); // Get general properties. var generalProps = sheet.GetBeamGeneralProperties(); Logger.Instance.Info("+----+------------------------+--------+-------+---------------+-----------------+--------+--------------+------------+--------+-----------+-------+----------------------+--------+--------+--------+"); Logger.Instance.Info($"|{"Beam",4}|{"Description",-24}|{"Field ID",-8}|{"Visible",-7}|{"Delivery",-15}" + $"|{"Treatment Unit",-17}|{"Modality",-8}|{"Algorithm",-14}|{"Energy",-12}|{"MU / Fx",8}|{"Setup",-11}" + $"|{"SSD(cm)",7}|{"Isocenter Location",-22}|{"X(cm)",8}|{"Y(cm)",8}|{"Z(cm)",8}|"); Logger.Instance.Info("+----+------------------------+--------+-------+---------------+-----------------+--------+--------------+------------+--------+-----------+-------+----------------------+--------+--------+--------+"); foreach (var prop in generalProps) { Logger.Instance.Info($"|{prop.BeamID,4}|{prop.BeamDescription,-24}|{prop.FieldID,-8}|{prop.IsVisible,-7}|{prop.Delivery,-15}" + $"|{prop.TreatmentUnit,-17}|{prop.Modality,-8}|{prop.Algorithm,-14}|{prop.Energy,-12}|{prop.MUFx,8:F2}|{prop.Setup,-11}" + $"|{prop.SSD,7:F2}|{prop.BeamIso.IsocenterLocation,-22}|{prop.BeamIso.IsoX,8:F2}|{prop.BeamIso.IsoY,8:F2}|{prop.BeamIso.IsoZ,8:F2}|"); } Logger.Instance.Info("+----+------------------------+--------+-------+---------------+-----------------+--------+--------------+------------+--------+-----------+-------+----------------------+--------+--------+--------+"); // Get geometry properties. var geomProps = sheet.GetBeamGeometryProperties(); Logger.Instance.Info("+----+------------------------+-------+-----------+---------------+----------+-----+------------+------------+------------+------------+"); Logger.Instance.Info($"|{"Beam",4}|{"Description",-24}|{"SSD(cm)",7}|{"Gantry(deg)",11}|{"Collimator(deg)",15}|{"Couch(deg)",10}|{"Asym",-5}" + $"|{"Width1(cm)",12}|{"Width2(cm)",12}|{"Length1(cm)",12}|{"Length2(cm)",12}|"); Logger.Instance.Info("+----+------------------------+-------+-----------+---------------+----------+-----+------------+------------+------------+------------+"); foreach (var prop in geomProps) { Logger.Instance.Info($"|{prop.BeamID,4}|{prop.BeamDescription,-24}|{prop.SSD,7:F2}|{prop.Gantry,11:F1}|{prop.Collimator,15:F1}|{prop.Couch,10:F1}|{prop.IsAsym,-5}" + $"|{prop.Width1,12:F2}|{prop.Width2,12:F2}|{prop.Length1,12:F2}|{prop.Length2,12:F2}|"); } Logger.Instance.Info("+----+------------------------+-------+-----------+---------------+----------+-----+------------+------------+------------+------------+"); // Get treatment aids properties. var trtmtaidsProps = sheet.GetTreatmentAidsProperties(); Logger.Instance.Info("+----+------------------------+----------------+-----+-------------+-----+-----+-------------+-----+--------+-----+"); Logger.Instance.Info($"|{"Beam",4}|{"Description",-24}|{"Wedge ID",-16}|{"Angle",5}|{"Orient",-13}|{"Port",-5}|{"MLC",-5}|{"Applicator ID",-13}|{"Bolus",-5}|{"SBD(cm)",8}|{"Couch",-5}|"); Logger.Instance.Info("+----+------------------------+----------------+-----+-------------+-----+-----+-------------+-----+--------+-----+"); foreach (var prop in trtmtaidsProps) { Logger.Instance.Info($"|{prop.BeamID,4}|{prop.BeamDescription,-24}|{prop.WedgeID,-16}|{prop.Angle,5}|{prop.Orient,-13}|{prop.Port,-5}|{prop.MLC,-5}|{prop.ApplicatorID,-13}|{prop.Bolus,-5}|{prop.SBD,8:F2}|{prop.Couch,-5}|"); } 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); } } } }