Varian-Code-Samples icon indicating copy to clipboard operation
Varian-Code-Samples copied to clipboard

How would I ask for user input?

Open sama2689 opened this issue 2 years ago • 6 comments

I am looking to create a BED/EQD2 calculator where the user can specify the structure name they are interested in, as well as an alpha beta ratio, and the software can calculate the BED and EQD2 using these known values. However, console inputs don't seem to work with ESAPI. MessageBoxes appear, but when asking for user input, the console does not pop up and so a command like string structure = Console.ReadLine(); is being skipped over. Is there some way to have user input values for this? Thanks

optional: I'd also ideally like this to be in an interactive GUI, where the user can change the AB ratio and structure of interest and with it the calculation will upodate

sama2689 avatar Oct 12 '21 12:10 sama2689

Hi Sama, I think this should work, but your variable structure will be a string. Perhaps you could try something like

structureId = Console.ReadLine();
structure = structureSet.FirstOrDefault(x=>x.Id == structureId);

Alternatively, if you're looking for a GUI approach, feel free to try out: https://github.com/WUSTL-ClinicalDev/DVHEquivalenceCalculator If you need help getting that installed, I'm happy to help. Just shoot me an email directly ([email protected]).

mattcschmidt avatar Oct 12 '21 15:10 mattcschmidt

Thanks for the response Matt! I am quite new to this so unfortunately may need some things spelled out for me. There are some errors that arise when I tried using your code, When I tried your suggestion visual studio complains about the following:

  1. the name 'structureID' does not exist in the current context, the same error appears for the name 'structure' and 'structureSet'

Here is my full code and this is on a single file plug-in template created by the script wizard. Would love to check out the GUI approach, but I am currently trying to walk before I run, but will likely move to this going forward!

using System;
using System.Linq;
using System.Text;
using System.Windows;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using VMS.TPS.Common.Model.API;
using VMS.TPS.Common.Model.Types;

[assembly: AssemblyVersion("1.0.0.1")]

namespace VMS.TPS
{
  public class Script
  {
    public Script()
    {
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    public void Execute(ScriptContext context /*, System.Windows.Window window, ScriptEnvironment environment*/)
    {
            Patient pat = context.Patient;// TODO : Add here the code that is called when the script is launched from Eclipse.
            structureId = Console.ReadLine();
            structure = structureSet.FirstOrDefault(x => x.Id == structureId);


        }
  }
}

sama2689 avatar Oct 12 '21 15:10 sama2689

Hi Sama,

Try the following.

public void Execute(ScriptContext context /*, System.Windows.Window window, ScriptEnvironment environment*/)
    {
            Patient pat = context.Patient;// TODO : Add here the code that is called when the script is launched from Eclipse.
            var structureSet = context.StructureSet;
            structureId = Console.ReadLine();
            structure = structureSet.FirstOrDefault(x => x.Id == structureId);
            if(structure!=null)
            {
                  Console.WriteLine(String.Format("Structure {0} with volume {1:F1}cc",structure.Id,structure.Volume));
            }
            else
            {
                  Console.WriteLine("Could not find structure" + structureId);
            }


        }

mattcschmidt avatar Oct 12 '21 16:10 mattcschmidt

Sorry! Major mistake.

public void Execute(ScriptContext context /*, System.Windows.Window window, ScriptEnvironment environment*/)
    {
            Patient pat = context.Patient;// TODO : Add here the code that is called when the script is launched from Eclipse.
            var structureSet = context.StructureSet;
            var structureId = Console.ReadLine();
            structure = structureSet.Structures.FirstOrDefault(x => x.Id == structureId);
            if(structure!=null)
            {
                  Console.WriteLine(String.Format("Structure {0} with volume {1:F1}cc", structure.Id, structure.Volume));
            }
            else
            {
                  Console.WriteLine("Could not find structure" + structureId);
            }


        }

mattcschmidt avatar Oct 12 '21 17:10 mattcschmidt

Hi Matt, I am having the same issues with the updated version of your code. "structure" is underlined by VS and so it runs into an error. Additionally, Eclipse does not let me launch the console (nothing appears) for either variable display nor variable input. I have to do this via GUI I think but this is quite a complex process (even though I only really want to take in two strings and display two outputs)

sama2689 avatar Dec 10 '21 14:12 sama2689

again, another mistake from trying to type this raw without an IDE.... structure should have a "var" before it.

mattcschmidt avatar Dec 10 '21 18:12 mattcschmidt