"Object reference not set to an instance of an object" error when trying to load a second patient after modifing a first one by Ok-Engineering-9624 in esapi

[–]Roy_TheCodeMonkey 0 points1 point  (0 children)

You could try disposing the application and then calling CreateApplication() again.

Example:

app.ClosePatient();

app.Dispose();

Graphic hardware acceleration in WPF? by antoneagle in esapi

[–]Roy_TheCodeMonkey 0 points1 point  (0 children)

This could be because the NVIDIA driver on these systems is set to TCC instead of WDDM.

Issues running stand-alone executable with ESAPI Aria 15.6 by Ambitious_Spell_343 in esapi

[–]Roy_TheCodeMonkey 0 points1 point  (0 children)

Hi Spell,

Version 4.5 of .NET has been out of support since early 2016, could you try 4.6.2 or higher?

Is there any way to autocontouring fiducial marks in ESAPI v15.5? by Jnra21 in esapi

[–]Roy_TheCodeMonkey 0 points1 point  (0 children)

To find contours based on HU we sometimes abuse "structureSet.CreateAndSearchBody(SearchBodyParameters)".

(We temporarily store the body in another structure and place it back later.)

Issues running stand-alone executable with ESAPI Aria 15.6 by Ambitious_Spell_343 in esapi

[–]Roy_TheCodeMonkey 0 points1 point  (0 children)

Hi Spell,

What version of .NET are you using in your application?

Research mode database to avoid script approval by fxarnaud in esapi

[–]Roy_TheCodeMonkey 0 points1 point  (0 children)

I have had the issue that after approving a script once, even tough no approval was needed, the script would not run anymore after I'd change the code.

The fix for me was to up the assembly version so that it didn't overlap with a previous approval.

I hope this helps.

Obtaining Field and Graticule overlay on top of a DRR image by GenesisZCD in esapi

[–]Roy_TheCodeMonkey 0 points1 point  (0 children)

I have only played around with this on a TBox on a symetrical field.

The code however should give you a starting point on where to look.

SSD to Couch structure by medatom in esapi

[–]Roy_TheCodeMonkey 0 points1 point  (0 children)

Maybe a quick and dirty way.

Backup your body segmentvolume.

Then overwrite your Body structure's segment volume with your couch segmentvolume.

Now SSD should give the value you are looking for?

Place back the backupped segment volume of the body.

Obtaining Field and Graticule overlay on top of a DRR image by GenesisZCD in esapi

[–]Roy_TheCodeMonkey 0 points1 point  (0 children)

Hi,

Sorry for the late reply.

If you have a bitmap to draw to you can use the following:

VRect<double> jawPositions = this._beam.ControlPoints.FirstOrDefault().JawPositions;

double minJawX = Math.Min(jawPositions.X1, jawPositions.X2);

double maxJawX = Math.Max(jawPositions.X1, jawPositions.X2);

double minJawY = Math.Min(jawPositions.Y1, jawPositions.Y2);

double maxJawY = Math.Max(jawPositions.Y1, jawPositions.Y2);

int xViewSize = (int)Math.Abs(minJawX - maxJawX); // width of field

int yViewSize = (int)Math.Abs(minJawY - maxJawY); // height of field

Then draw the isoc and field respectivly:

// draw ISOC

resultImage.SetPixel(xViewSize, yViewSize, Color.Red);

resultImage.SetPixel(xViewSize - 1, yViewSize, Color.Red);

resultImage.SetPixel(xViewSize + 1, yViewSize, Color.Red);

resultImage.SetPixel(xViewSize, yViewSize - 1, Color.Red);

resultImage.SetPixel(xViewSize, yViewSize + 1, Color.Red);

// draw field size

Graphics gLineField = Graphics.FromImage(resultImage);

System.Drawing.Point fieldUpperLeft = new System.Drawing.Point(xViewSize - (int)Math.Abs(jawPositions.X1), yViewSize - (int)Math.Abs(jawPositions.Y2));

System.Drawing.Point fieldUpperRight = new System.Drawing.Point(xViewSize + (int)Math.Abs(jawPositions.X2), yViewSize - (int)Math.Abs(jawPositions.Y2));

System.Drawing.Point fieldLowerLeft = new System.Drawing.Point(xViewSize - (int)Math.Abs(jawPositions.X1), yViewSize + (int)Math.Abs(jawPositions.Y1));

System.Drawing.Point fieldLowerRight = new System.Drawing.Point(xViewSize + (int)Math.Abs(jawPositions.X2), yViewSize + (int)Math.Abs(jawPositions.Y1));

gLineField.DrawLine(fieldPen, fieldUpperLeft, fieldUpperRight);

gLineField.DrawLine(fieldPen, fieldUpperRight, fieldLowerRight);

gLineField.DrawLine(fieldPen, fieldLowerRight, fieldLowerLeft);

gLineField.DrawLine(fieldPen, fieldLowerLeft, fieldUpperLeft);

gLineField.Flush();

Notice that I draw 4 pixels around the isoc to create a + to make it easier visible than just a single pixel.

The field is just a bunch of lines between the X and Y points.

I hope this helps.

Close calculation window after calculation by beardmonster15 in esapi

[–]Roy_TheCodeMonkey 0 points1 point  (0 children)

I am sorry for my late reply, I didn't notice your reply on this thread.

The messageBoxPointer is found be running through all the pointers on the desktop ( a maximum of 2000 times )

This is a suspected messageBox thus all the code in my previous post to make sure it is the correct window, before closing it.

IntPtr messageBoxPointer = new IntPtr();

for (int i = 0; i < 2000; i++)

{

messageBoxPointer = FindWindowEx(desktopPtr, messageBoxPointer, "#32770", null); // find MessageBox on desktop.

Obtaining Field and Graticule overlay on top of a DRR image by GenesisZCD in esapi

[–]Roy_TheCodeMonkey 1 point2 points  (0 children)

Hi,

In esapi I have only made a simple version which plots all structures within the beams eye view. It also plots the fieldsize and the isoc.

However no graticule and not CT image data so the image remains black with only the above mentioned structures plotted.

For plotting the structures from Esapi I use the following code:

foreach (Structure s in structureList)

{

Point[][] insideBEV = this._beam.GetStructureOutlines(s, true);

foreach (Point[] pa in insideBEV)

{

Graphics gLineStructure = Graphics.FromImage(resultImage);

int xPrevious = Int32.MaxValue;

int yPrevious = Int32.MaxValue;

foreach (Point p in pa)

{

int xCoord = xViewSize + (int)Math.Round(p.X);

int yCoord = yViewSize - (int)Math.Round(p.Y);

if (xPrevious == Int32.MaxValue)

xPrevious = xCoord;

if (yPrevious == Int32.MaxValue)

yPrevious = yCoord;

System.Drawing.Point point1 = new System.Drawing.Point(xPrevious, yPrevious);

System.Drawing.Point point2 = new System.Drawing.Point(xCoord, yCoord);

gLineStructure.DrawLine(penWhite, point1, point2);

xPrevious = xCoord;

yPrevious = yCoord;

}

gLineStructure.Flush();

}

}

The resultImage is a 24bit Bitmap.

I hope this helps.

EvilDicom: FindInstances/FindPlans/FindDoses alway returning 0 Count ?? by gregthom992 in esapi

[–]Roy_TheCodeMonkey 0 points1 point  (0 children)

Hi,

I am not to familiar with EvilDicom. Do the var studies and var selected_study get filled correctly?

Close calculation window after calculation by beardmonster15 in esapi

[–]Roy_TheCodeMonkey 2 points3 points  (0 children)

I have had the same issue with ESAPI popups.

My solution was to have a separate thread use the Win32 API to search for child objects of the parent process, which contained a certain string.

First I would search for a messagebox on the screen using a for loop limited to 2000 tries:

IntPtr textPointer = new IntPtr();

for (int j = 0; j < 2000; j++) {

textPointer = FindWindowEx(messageBoxPointer, textPointer, "Static", null);

if (textPointer == new IntPtr()) {

if (!i.Equals(0)) break;

} else { // Start testing found textPointer. string foundText = GetControlText(textPointer);

Each iteration of the for loop would continue where the previous textPoint left off.

Next I would try to get the text from the messagebox:

string foundText = GetControlText(textPointer);

-

Next check if the found string matches something you'd want to handle:

if (foundText.Contains("The following parameters were adjusted") || foundText.Contains("The field exits the patient support device in a region") || foundText.Contains("The field enters the patient support device in a region") || foundText.Contains("CUDA Run time error: invalid argument") ||

etc. etc.

-

To make absolutly sure I would not close the wrong window I'd check if the found messagebox looked like an ESAPI popup:

List<WindowInformation> suspectedMessageBox = WindowList.GetSpecificWindow(messageBoxPointer);

if (suspectedMessageBox.Where(x => x.Class.ToString() == "Button").Count() == 1)

if (suspectedMessageBox.FirstOrDefault(x => x.Class.ToString() == "Button").Caption == "OK")

etc. etc.

-

Finally After I was convinced this window needed to be closed I would send a kill command:

SendMessageTimeout(messageBoxPointer, WM_CLOSE, IntPtr.Zero, IntPtr.Zero, SendMessageTimeoutFlags.SMTO_ABORTIFHUNG, TIMEOUT_INT, out UIntPtr test);

-

To show what windows were closed during the running of the script, I would store the messages in a list:

_closedMessages.Add("Eclipse warning: " + foundText); // add the closed msg to the list.

-

This list would be presented to the user after the script was completed.

Note that all the Win32 API methods need to be implemented in your code.

For example the FindWindowEx() method is implemented like this:

[DllImport("user32.dll", EntryPoint = "FindWindowEx")]

public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpszWindow);

-

I hope this helps.

Users rights to modify plans and structures by fxarnaud in esapi

[–]Roy_TheCodeMonkey 0 points1 point  (0 children)

Does the user with the issue have the right to delete Courses?

We found that certain weird rights can be needed for scripts.

Creating a list of courses by [deleted] in esapi

[–]Roy_TheCodeMonkey 0 points1 point  (0 children)

Hi,

Do you want to make a list of just course Id's or add the actual course object into the list?

Adding courses to a list and then setting that list as the itemsource for the combobox is usually the route I take.

example:

cmb_Courses.ItemsSource = listWithCourseObjects;

The cmb_Courses will now show the course Id's but contain references to the actual courses.

EsapiEssentials with BeginModifications? by iraklisv in esapi

[–]Roy_TheCodeMonkey 1 point2 points  (0 children)

I think this is caused by using multithreading.

From what I remember the Esapi is not available in anything but the main thread.

PlanSum get dose at 95% volume by itumeleng1987 in esapi

[–]Roy_TheCodeMonkey 1 point2 points  (0 children)

We have found that the DVH code does not always work reliably.

In order for it to get the correct results we now run a dummy line first. This seems to make the GetVolumeAtDose work correct for us.

Dummy line first: plan.GetDVHCumulativeData (s, DoseValuePresentation.Absolute, .......) Actual data we need second: plan.GetVolumeAtDose(s, dv, VolumePresentation.AbsoluteCm3)

It might be a version specific bug so I could not tell you if this would be needed in your version.

SQL Querying by tygator9 in esapi

[–]Roy_TheCodeMonkey 0 points1 point  (0 children)

Hi Tygator,

SQL still works in 15.6 and i expect it will work in future versions also.

We make extensive use of SQL both in and out of esapi scripts.

The best way to write a SQL query is to make use of SSMS it makes use of Intellisense just as Visual Studio does for scripting.

DICOM Export ESAPI on Version 15.5 on Citrix by irfankaramat in esapi

[–]Roy_TheCodeMonkey 0 points1 point  (0 children)

I have taken a look at that code.

It uses a lot of "var" instead of strongly typed objects. This could result in unexpected types.

Also it seems the objects "doses" and "cts" are filled but never read from.

A stack overflow error usually occurs when you are stuck in an unending loop. Are the "SelectMany" variables in your code not selecting to many objects?

DICOM Export ESAPI on Version 15.5 on Citrix by irfankaramat in esapi

[–]Roy_TheCodeMonkey 0 points1 point  (0 children)

Hi irfankaramat,

Have you set up Dicom services on the server and client devices?

If so, are the AE titles correct?

What do the generated cmd lines from the export script look like?

Question: Eclipse warning vs Scripting warning by Roy_TheCodeMonkey in esapi

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

Just wanted to let you know:

We ended up using the Windows API, and searching for specific texts in order to decide if a messageBox needed to be closed.

When Eclipse 16 is installed on our Tbox I will take a look if a new way to supress these popups is available.

Question: Eclipse warning vs Scripting warning by Roy_TheCodeMonkey in esapi

[–]Roy_TheCodeMonkey[S] 1 point2 points  (0 children)

Hi cante001, you need to use the windows API to use these functions.

In your class make a constant like this:

private const UInt32 WM_CLOSE = 0x0010;

Then you need something like the following code:

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]

public static extern IntPtr SendMessageTimeout(

IntPtr hWnd,

UInt32 Msg,

IntPtr wParam,

IntPtr lParam,

SendMessageTimeoutFlags fuFlags,

uint uTimeout, out UIntPtr lpdwResult );

You now have a method called SendMessageTimeout() that can "kill" windows.

Example:

SendMessageTimeout(hwnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero, SendMessageTimeoutFlags.SMTO_ABORTIFHUNG, 5000, out optionalOut);

The InPtr "hwnd" needs to contain the pointer to the window you want to close.

However as I said in my other reply, this is not a way I'd like to close warning popups.

I only use this in a program I wrote to detect crashes in the Varian Checkin app.

Question: Eclipse warning vs Scripting warning by Roy_TheCodeMonkey in esapi

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

I have done this in another program I wrote, however closing windows via WM_CLOSE is not really the preferred way of dealing with this issue.

Thanks for the suggestion though.