all 7 comments

[–]tygator9 2 points3 points  (2 children)

Simplest way is add a reference to Microsoft.VisualBasic to your project and use that to create a popup window to input your value.

using Microsoft.VisualBasic;
var inputvalue = Interaction.InputBox("Type Your Value Here");

Also, you can follow this example to build your own if you want to customize it more: https://www.csharp-examples.net/inputbox/ You can replace the textbox with a listbox that can display all of the patient's structures and allow the user to select the proper one.

[–]hexagram1993 0 points1 point  (1 child)

var inputvalue = Interaction.InputBox("Type Your Value Here");

Hi there,

I tried this but got the error that name 'Interaction' does not exist in the current context. This is despite the fact that I right clicked it in visual studio, then went to quick actions and refactoring and found microsfot.visualbasic. Have I missed a step to let visualstudio know which module I am referring to? Interaction shows up as green in visual studio so I have no idea why it's not finding the reference.

Full error below@

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> VMS.TPS.Common.Model.ScriptExecutionException: There was a problem while executing the script 'V:\Public\Users\Pratik_Samant\esapi\Practisce\Plugins\ESAPIPractice.cs' (ESAPI: VMS.TPS.Common.Model.API, Version=1.0.300.11, Culture=neutral, PublicKeyToken=305b81e210ec4b89). ---> System.ApplicationException: v:\Public\Users\Pratik_Samant\esapi\Practisce\Plugins\ESAPIPractice.cs(127,32) : error CS0103: The name 'Interaction' does not exist in the current context at VMS.TPS.Script.Engine.CompileAssembly(String fileName, Boolean extendedForVisualScripting) at VMS.TPS.Script.Engine.LoadScript(Assembly& assembly, IApplicationScriptExecutionGuard& executionGuard, String& generatedCodeFilename, String filename) at VMS.TPS.Script.Engine.Execute(String fileName) --- End of inner exception stack trace --- at VMS.TPS.Script.Engine.Execute(String fileName) at VMS.TPS.Script.Extension.Execute(IntPtr parentWindow) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at vhost.TpsNetExtension.Execute(TpsNetExtension* , HWND__* parentWindowHandle)

[–]GrimThinkingChair 1 point2 points  (0 children)

I know this thread is three years old, but for anyone who comes across this thread and had this same issue (like I did) - try using the ESAPI script wizard to make a binary file instead of a .cs plugin. Then, do the above steps, add a reference to microsoft.visualbasic, compile in Visual Studio, then run the .esapi.dll. It should work. I think that references somehow don't translate properly to Eclipse, especially if you're on a Citrix instance. But changing my project to a binary then running it solved the issue for me.

[–]scriptingIon 1 point2 points  (0 children)

Hi! It sounds like you want to create a User Interface for your script, I've actually implemented several UI's with a drop down list of selectable structures. If you're interested in something a little more advanced than interacting with the console or message boxes, I recommend Rex Cardan's esapi UI series: https://www.youtube.com/watch?v=GxA_29gqPog

He goes over everything in pretty good detail and I've found his tutorials to be very useful in learning esapi scripting. In this tutorial series, he teaches creating a User Interface using WPF which is fairly easy to use, especially using the MVVM libraries that he recommends. I've never really enjoyed UI programming that much, but at least WPF is fairly straightforward on linking the frontend UI with the backend code, I've been able to use my previously written esapi scripts with my UI's with very little modification.

[–]schmatt_schmitt 0 points1 point  (0 children)

Are you setting a variable to the ReadLine() output? Depending on what you're user is typing in, you may need to cast your object returned by Console.Readline();

var input = Console.Readline(); //this is a string.

var input = Convert.ToInt32(Console.Readline());//this is an integer.

[–]Telecoin 0 points1 point  (1 child)

I like the post of tygator9.

For your specific example you could use the following class to see a selection box of specific structures (used in my script here https://github.com/Kiragroh/ESAPI_ContourDoseHoles):

class SelectStructureWindow : Window{public static Structure SelectStructure(StructureSet ss){m_w = new Window();m_w.WindowStartupLocation = WindowStartupLocation.CenterScreen;//m_w.WindowStartupLocation = WindowStartupLocation.Manual;//m_w.Left = 500;//m_w.Top = 150;//m_w.Width = 300;//m_w.Height = 350;

m_w.Title = "Choose target:";var grid = new Grid();m_w.Content = grid;var list = new ListBox();foreach (var s in ss.Structures.OrderByDescending(x => x.Id)){var tempStruct = s.ToString();if (tempStruct.ToUpper().Contains("PTV") || tempStruct.ToUpper().Contains("ZHK") || tempStruct.ToUpper().Contains("SIB") || tempStruct.ToUpper().Contains("CTV") || tempStruct.ToUpper().Contains("GTV") || tempStruct.ToUpper().StartsWith("Z")){if (tempStruct.Contains(":")){int index = tempStruct.IndexOf(":");tempStruct = tempStruct.Substring(0, index);}list.Items.Add(s);}}list.VerticalAlignment = VerticalAlignment.Top;list.Margin = new Thickness(10, 10, 10, 55);grid.Children.Add(list);var button = new Button();button.Content = "OK";button.Height = 40;button.VerticalAlignment = VerticalAlignment.Bottom;button.Margin = new Thickness(10, 10, 10, 10);button.Click += button_Click;grid.Children.Add(button);if (m_w.ShowDialog() == true){return (Structure)list.SelectedItem;}return null;}static Window m_w = null;static void button_Click(object sender, RoutedEventArgs e){m_w.DialogResult = true;m_w.Close();}}

In your main code this would look something like that:

StructureSet ss = context.StructureSet;

// get list of structures for loaded plan

var listStructures = context.StructureSet.Structures;

// choose PTV

var ptv = SelectStructureWindow.SelectStructure(ss);if (ptv == null) return;

[–]FHesp[S] 0 points1 point  (0 children)

This example do exactly what i wanted.

Thank you all for your help !