VarianAPIs / Varian-Code-Samples

Code samples for ESAPI and other Varian APIs and web services.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How would I ask for user input?

sama2689 opened this issue · 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

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 (matthew.schmidt@wustl.edu).

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);


        }
  }
}

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);
            }


        }

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);
            }


        }

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)

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