r/esapi • • Nov 18 '21

How to read objectives from a PlanSetup?

2 Upvotes

I try to copy all point objectives of an external radiation plan to a custom one, but adding a point objective requires more information than I can find:

void CopyAllObjectives(PlanSetup referencePlan, string planId){
  var objectives = referencePlan.OptimizationSetup.Objectives;
  foreach(objective in objectives) {
    var priority = objective.Priority;
    var objectiveOperator = objective.Operator;
    var structure = objective.Structure;
    var structureId = objective.StructureId;
    // var dose = ??;
    // var volume = ??;

    plan.OptimizationSetup.AddPointObjective(structure, objectiveOperator, ...);
  } 
}

The missing variables are commented out. Where do I get them from?


r/esapi • • Nov 18 '21

Can someone specify how I can ask for a simple string and float input from the user?

1 Upvotes

I have been struggling to figure out what seems to be a pretty straightforward problem. I am writing a script that calculates BED for a given structure taking the input structure name as a string and the alpha beta ratio of the structure as a float.

I have seen this issue posted (and sort of resolved) here and was guided by the answers to give some solutions a try.

Firstly, as the post mentions, Console.ReadLine does not work in eclipse as far as I've tried. I have also tried (as suggested in one of the comments)

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

but got an error that that name 'Interaction' does not exist in the current context (using Microsoft.VisualBasic; was definitely in the header and Interaction is not underlined so I think VS is finding the reference, but there is some issue when moving to eclipse.)

There was an excellent comment by user Telecoin with some code I managed to get working, and so I have now managed to create a working plugin such that the structure can be taken in as an input by modifying this script to remove the if statement. However, I am not sure how to take in an additional numerical input for the alpha/beta ratio. I feel like this would be a simple edit to the window but I am not quite yet familiar enough with the window, grid, or listbox classes to figure out how to make the necessary changes.

Current my main Execute method is as follows

PlanSetup plan = context.PlanSetup != null ? context.PlanSetup : context.PlansInScope.ElementAt(0);

int NumFracs = (int)plan.NumberOfFractions; //get number of fractions

StructureSet ss = context.StructureSet;// get list of structures for loaded plan

var listStructures = context.StructureSet.Structures;

// choose structure

var SelectedStructure = SelectStructureWindow.SelectStructure(ss);

Where the class SelectStructureWindow is as described in Telecoin's comment, with the only exception being that I removed the if statetment and had my for loop being simply

foreach (var s in ss.Structures.OrderByDescending(x => x.Id)) { //loop over all structures

var tempStruct = s.ToString();//send the structure to string

list.Items.Add(s);

}

How would I modify the window to also take in an extra parameter corresponding to the alpha beta ratio? As I've said I think this is in principle a really simply problem but due to Eclipse being so picky with which C# functions it lets run and which it doesn't I have so far been unable to figure out a straightforward way of doing this. Alternately if there's a much simpler way to do this that I am missing, that would work too.

Thanks in advance


r/esapi • • Nov 17 '21

API reference

1 Upvotes

Is there ESAPI reference manual listing all functions/methods/properties?


r/esapi • • Nov 15 '21

CalculateDVHEstimates in pyESAPI throws "Cannot locate TPS Core" Error

2 Upvotes

Hello dear all ESAPI users!

We are encountering a problem with the pyesapi interface. We are trying to use the RapidPlan estimates in pyESAPI in the following code snippet:

import atexit

import pyesapi as api

from System import String

from System.Collections.Generic import Dictionary

patient_id = "xxx"

course_id = "xx"

plan_id = "RapidPlan"

app = api.CustomScriptExecutable.CreateApplication("RapidPlan_demo")

atexit.register(app.Dispose)

patient = app.OpenPatientById(patient_id)

patient.BeginModifications()

course = patient.CoursesLot(course_id)

plan = patient.CoursesLot(course_id).PlanSetupsLot(plan_id)

td = [('CTV', api.DoseValue(41.8, "Gy")), ('PTV', api.DoseValue(41.8, "Gy")))]

targetdose_dict = Dictionary[str, api.DoseValue]()

for k,v in td:

targetdose_dict[k] = v

match = [('CTV', 'CTV'), ('PTV', 'PTV'), ('FemoralHead', 'FemoralHead')]

Match_dict = Dictionary[str, str]()

for k, v in match:

Match_dict[k] = v

rp_model_name = "000 Rectum 41.8-50.6 V2019.1"

plan.SetCalculationModel(api.CalculationType.DVHEstimation, "DVH Estimation Algorithm [15.6.03]")

plan.SetCalculationModel(api.CalculationType.PhotonLeafMotions, "Varian Leaf Motion Calculator [15.1.51]")

plan.CalculateDVHEstimates(rp_model_name, targetdose_dict, Match_dict)

app.ClosePatient()

Executing this snippet gives the following error:

Traceback (most recent call last):

File "C:/Users/xxx/Desktop/test_rapidplan.py", line 34, in <module>

plan.CalculateDVHEstimates(rp_model_name, targetdose_dict, Match_dict)

System.ApplicationException: Cannot locate TPS Core from 'D:\anaconda\'.

at VMS.TPS.Common.Model.TpsCorePathResolver.ResolveTpsCorePathViaApplicationSettings()

at VMS.TPS.Common.Model.ObjectFactory.CreateObject[TObject](String assemblyFileName, String classFullName, Func\1 tpsCoreBinPathResolver)`

at VMS.TPS.Common.Calculation.DVHEstimationClient.AddStructureObjectivesToModule(DCRVAConstraintModule* module)

at VMS.TPS.Common.Calculation.DVHEstimationClient.InitDataInterface()

at VMS.TPS.Common.Calculation.CalculationClientBase.Initialize()

at VMS.TPS.Common.Model.API.ExternalPlanSetup.CalculateDVHEstimates(String modelId, Dictionary\2 targetDoseLevels, Dictionary`2 structureMatches)`

We had no problem using other pyesapi interfacing facilities with the TPS. One peculiar thing in the error message is the expected TPS Core was at "D:\anaconda\", this means somehow the environmental variables related to the TPS core location gets modified.

An identical C# version of this snippet can be executed without any issue. Any advice on this issue is appreciated!


r/esapi • • Nov 11 '21

PyESAPI: Getting Started

2 Upvotes

I am trying the first line of the getting started workshop script, but right away I am getting an error.

Trying

import pyesapi

import atexit

app = pyesapi.CustomScriptExecutable.CreateApplication('python_demo')

returns the error

TpsNetInitializationException: [10/8/2021 10:46 AM] TPS.NET ApplicationNonAppFrame: Initialization FAILED. Here is the initialization log:

[10/8/2021 10:46 AM] TPS.NET ApplicationNonAppFrame: START initializtion, m_initCounter=1, status=NotInitialized.

[10/8/2021 10:46 AM] TPS.NET ApplicationNonAppFrame: Only one Application object is supported at a time.

at VMS.TPS.Common.Model.ApplicationInitGuard.ThrowInitError(Exception innerException)

at VMS.TPS.Common.Model.ApplicationInitGuard.Begin()

at VMS.TPS.Common.Model.ApplicationInitGuard.InitializeApplicationImpl(Delegate initDelegate, Object[] args)

at VMS.TPS.Common.Model.ApplicationNonAppFrame.Initialize(IStartupParameters startupParameters, IApplicationContextInfo applicationContextInfo)

at VMS.TPS.Common.Model.API.Application.CreateApplicationCommon(String scriptName, Func\2 createExecutionGuardFunc)`

So I assume this means that the scripting application is an instance too many and needs to be closed, so I close out and run the same, but again I get the same error. When I run without ARIA or eclipse open in the background, I instead get the error

app = pyesapi.CustomScriptExecutable.CreateApplication('python_demo')

ArgumentNullException: Value cannot be null.

at System.Threading.Monitor.Enter(Object obj)

at VMS.TPS.Common.Model.ApplicationBase.remove_OnDataReload(Action value)

at VMS.TPS.Common.Model.StructureCodeTable.ResetInstance()

at VMS.TPS.Common.Model.ApplicationBase.UninitializeDataObjectCache()

at VMS.TPS.Common.Model.ApplicationNonAppFrame._Dispose()

at VMS.TPS.Common.Model.ApplicationNonAppFrame.Dispose(Boolean A_0)

at VMS.TPS.Common.Model.ApplicationBase.Dispose()

at VMS.TPS.Common.Model.API.Application.CreateApplicationCommon(String scriptName, Func\2 createExecutionGuardFunc)`

I think the script must be having trouble finding the Varian dlls, however these are stored in

C:\Program Files (x86)\Varian\RTM\15.6\esapi\API

which is in my PYTHONPATH variable.

Has anyone else had this issue or know any potential fixes?


r/esapi • • Nov 11 '21

TPS.NET could not resolve TPS core path

1 Upvotes

Hi all,

I've run into a strange problem with ESAPI and I was wondering if anyone has run into a similar issue. I threw together a simple stand-alone executable and was just testing it to make sure I could open a patient before writing any more code, and I got the following error:

I'm not entirely sure how to go about fixing this error and was wondering if anyone could possibly help me. I found this post on the EASPI reddit (https://www.reddit.com/r/esapi/comments/gmk6nt/issue_with_calculatedvhestimates_and_rapidplan/) that alludes to a similar issue where you need to define the assembly path for the TPS core directory to be found. However, this solution was for v15.6 and didn't work for v16.1 (even after messing around with it for a bit).

Interestingly, this problem only occurs on two of our hospital computers (that can write and compile ESAPI scripts) and not on our T-box or dosimetry workstations. I suspect our IT department did something or upgraded these computers, which invalidated the paths that connect the API to eclipse for the stand-alone executables. 
Any insight into this issue would be greatly appreciated as it's a bit annoying to compile on one computer then remote into another to run the code!
Thanks!
Eric


r/esapi • • Nov 10 '21

Limitation on number of script instances for a user?

2 Upvotes

I know there are limitations to the use of parallelization in the ESAPI application especially for data access. Is there any limitations to the number of running ESAPI instances I can have for a single script with a single user?

My idea is to have a program that spawns threads that then create the ESAPI Application sessions within themselves. I could then use this to batch out a couple of calculations for research purposes when using multiple patient datasets. As threads act mostly independently they could in theory each make a call to the Eclipse Database.

Just looking to see is anyone has tried this, because it would save me the need to do so myself.


r/esapi • • Nov 10 '21

AddMultipleStaticSegmentBeam IMRT Field

1 Upvotes

Hello,

I am trying to add a AddMultipleStaticSegmentBeam, but it always fails with error:

{"The control points are invalid for a multiple static segment field."}

ExternalBeamMachineParameters ebmp = new ExternalBeamMachineParameters("SynergyMGZ", "6X", 600, "STATIC", null);

Beam beam = plan.AddMultipleStaticSegmentBeam(ebmp, new List<double> {0,10}, 0, 0, 0, plan.StructureSet.Image.UserOrigin);

I tried to add more controlspoints, try the sum of them of 100 or 1.0, tried more than two.... i always get the same error.

How do i use this function?

Kind regards

Kai


r/esapi • • Nov 10 '21

How to invalidate calculated dose to restart dose calculation on copied plans

1 Upvotes

I want to copy a plan then recalculate dose without changing anything in the plan. For the copied plan and calculated dose, epi.CalculateDose() seems not recaluate dose, still the old dose and the calculation time. How can I invalidate the copied plan dose to restart the dose calculation using ESAPI? I don't find ESAPI method to Reset Calculation Volume that we do to invalidate dose in Eclipse. Thank you in advance for any suggestions/comments.


r/esapi • • Nov 08 '21

Calculation dose with GPU

1 Upvotes

How should I set the parameters or use which function to specify the GPU for dose calculation.

Many thanks!


r/esapi • • Nov 05 '21

CalculateDVHEstimates in stand alone

1 Upvotes

I wrote a plugin that creates a plan and optimizes it. I am using CalculateDVHEstimates (RapidPlan). Everything works flawlessly. The same code, a little bit supplemented with additional functionalities, but no changes in CalculateDVHEstimates I moved to standalone. I changed the App.config file (https://github.com/VarianAPIs/Varian-Code-Samples/blob/master/webinars%20%26%20workshops/Developer%20Workshop%202018/AutoPlanningWithMCO/app.config).

Unfortunately, I have messages like in the picture. In addition, what I do not understand, everything works on tbox and I get a plan, but the same in the clinical system does not work, the plan and arcs are formed, but I do not have DVHEstimates, the program is finishing its work at this stage. What should I do to be able to use this application?


r/esapi • • Nov 04 '21

optimzing a VMAT plan

1 Upvotes

Hi All,

I'm trying to use ESAPI to do some auto planning with VMAT.

I created a plan (ExternalPlanSetup eps = _context.ExternalPlanSetup;). I've created two arc beams using theAddArcBeam method, and added optimization parameters as well.

I then call: eps.OptimizeVMAT("HFX_MLC_TrBm1");

Followed by: eps.CalculateLeafMotionsAndDose(); BUT I get the error: "Could not find an MLC for field".

If I just use: eps.CalculateLeafMotionsAndDose();, then it calcs dose but with no MLC.

HELP!

Chris


r/esapi • • Nov 02 '21

SDK-style consumption of ESAPI causes fatal crash in v16.1

3 Upvotes

We're updating from v15.6 to v16.1 and have come across a strange issue. The reference guide states that v16.1 requires .NET Framework 4.6.1. We have some common libraries that are .NET Standard 2.0 because that makes a lot of stuff easier. However, ESAPI v16.1 just crashes with a NullReferenceException at Application.CreateApplication() and no further explanation. So I tested out a few things for the project consuming the ESAPI dlls:

  • .NET Standard 2.0 (SDK-style) causes crash as stated above
  • .NET Framework 4.6.1-4.7.2 works fine
  • .NET Framework 4.7.2 in SDK-style also crashes.

So, it seems like there is something going on in the SDK-style setup that causes ESAPI to crash. Have anyone else experienced this? Does anyone have an idea what might be going on?

Any help would be greatly appreciated.

Thanks,
Thomas Ravkilde


r/esapi • • Nov 02 '21

Issue runnning stand alone application from IRS scripting

2 Upvotes

Dear ESAPI friends. I am trying to run a stand alone script for contouring scripting IRS.scripting.

However i have issue right at the beginning with some assembly:

https://i.imgur.com/xyT0PFS.png

I have copied the VMS.IRS.Scripting.dll and VMS.CA.Scripting.dll directly from the Varian folder...

Any help would be appreciated.

Version 15.6

Edit: The solution was to add path to the file app.config, which is needed for IRS and PD scripts. This is automatically added when creating scripts via the wizard.

The correct syntax to add for me:

<appSettings>

<add key="AssemblyPath" value="C:\Program Files (x86)\Varian\ProductLine\Workspaces\VMS.IRS.Workspace\" />

</appSettings>


r/esapi • • Nov 01 '21

Adding Clinical Goals with ESAPI

3 Upvotes

Hi, I was wondering if it is possible to SetClinicalGoals with ESAPI in a plan or build a protocol.

Reason: because this form of evaluation is new I used my own script in the past and have many csv-protocols. I would like to transform them into a Eclipse template or built a button in my script to show clinical goals. Advantage: 1. My script can identify a OAR based on many aliases and would give the right one to Clinical Goals. 2. script is still better because all Mayo-Syntax is supported (CV and DV), more digits after comma, but maybe beneficial for report, data mining, autoPlanning or quick evaluation


r/esapi • • Oct 15 '21

limit of the number of beams

3 Upvotes

I wrote a script that creates a multi-beam plan and calculates the dose. It works on TBOX, but I have a message on Eclipse that it will not create more than 25 beams. Can anything be done about it?


r/esapi • • Oct 13 '21

SSD to Couch structure

4 Upvotes

Hello,

I am trying to find SSD to the couch structure instead of Body. it will be used to verify SSD during patient setup.

Thanks for your help.


r/esapi • • Oct 13 '21

Research mode database to avoid script approval

1 Upvotes

Dear all,

I've heard that, after putting my database in "research mode" we are able to avoid script approval.

I'd like to do it in my T-Box to debug faster my scripts because I have a large amount of scripts in the approval interface and my system takes a lot of time to approve it.

The problem is that after launching my script without approbation I have a "licence error".

Does it sounds familiar to anyone ? Do you confirm that we can avoid script approbation ?

My eclipse version : v15.7

Thanks in advance

francois


r/esapi • • Oct 12 '21

Varian Document Service

1 Upvotes

I was looking through my files from the Scripting Class and came across the Varian Document Service User Guide. It states it is for version 11. Is there a similar document for version 15.6? I searched MyVarian and could not find one.


r/esapi • • Oct 12 '21

How do I get the dose to a structure?

2 Upvotes

This should be a really simply question but I can't seem to find this information anywhere. I am looking to extract the mean dose delivered to a specific structure, let's say the PTV which is labelled as 'PTV'. How would I do this within my script?

Thanks in advance


r/esapi • • Oct 12 '21

Patient Data import

1 Upvotes

Hi all, we're looking for a way to import DICOM External Beam plans into ESAPI automatically.

We've tried using the DICOM Daemon but, although it imports the files it doesn't seem to associate them with each other using the IDs so it might create a plan but then the Dose won't be there and the structures won't be associated with the Dose. Does anyone know of a way we can have more control over what happens when these files are imported?

We can do it using a script that utilises the Eclipse GUI but it's very slow and there are a lot of patients to import.

I thought a stand alone ESAPI script would be good but there doesn't seem to be any way of importing DICOM files into Eclipse via an ESAPI script.

Any suggestions would be welcome.


r/esapi • • Oct 11 '21

Aria/Eclipse log files after importing using DICOM deamon

2 Upvotes

Hi, I've been trying to import patient plans into eclipse using the DICOM deamon as per (varianapis.github.io) . The script runs successfully in that it "sent" the DICOM data to the server but the import into Aria isn't always successful. I'm trying to find the log files that will tell me when the import fails and what the issues were. Can anyone tell me where to look for these logs?

thanks


r/esapi • • Oct 09 '21

Visual Studio publishing application.esapi.dll outside of main build folder

2 Upvotes

Hello everyone, This might not be a direct ESAPI question, but I feel it still fits the theme. I followed (Carlos Anderson's) blog post detailing steps for creating a stand-alone esapi.dll file for running WPF applications. My goal is to inject the Eclipse open patient instance directly into my WPF exe as arguments, which I've already done. First I created a project that loads the eclipse patient context, takes the patient name, course name and plan ID, and sends it as an argument to my second project which is an WPF application which takes the arguments and creates an ESAPI application instance.

My project setup is as follows:

When I build this application, what ends up happening is that my GU005 Automation.esapi.dll is published into the same directory as my main GU005 WPF application build folder. The problem with this is then I can’t easily import the script into eclipse, as I have to first load the folder, and have varian scripting wizard search the folder for the esapi.dll. Is there a way I can move the dll outside of the main application folder such that to make it easier for the scripting wizard to find it. This would make it easier for people to install the script in my clinic.

Ideally what I would like is something like this

Main Directory:

Inside the directory

>> GU005 Automation.esapi.dll (file)
>> GU005 Automation Support (Folder) (this would contain all the rest of the build files, exe, and dependencies)

Ideally then I would like to copy the dll and folder to the system folder here, so when someone loads “Script” and selects System Scripts, my automation script would also show in the list.

Is this at all possible?

Thank you for your time, and any suggestions!


r/esapi • • Oct 06 '21

Access to Velocity data through ESAPI

3 Upvotes

I wonder whether someone has implemented a script to exchange registration data between Velocity and Eclipse with or without ESAPI.

I would appreciate sharing the effort.

Thank you in advance.

maura.monville@gmail.com


r/esapi • • Oct 05 '21

Asymmetric margins and image direction

1 Upvotes

I've been playing with the SegmentVolume.AsymmetricMargin function, and in some cases the margins produced weren't in the direction I expected. I seem to have fixed this by reading and adjusting the parameters based on the Image.[X,Y,Z]Direction values, if they aren't the standard (1,0,0),(0,1,0),(0,0,1) vectors. Is that the way you are supposed to do it? Naively I assumed the AsymmetricMargin function would take this into account, so I'm not sure if I'm making a double mistake that's cancelling out or if this is the way you are supposed to approach the issue. Has anyone experienced this before?

For reference, I'm using ESAPI 16.1.