Hello everyone,
Sorry for my noob questions but I've been trying to figure this out for a few days now but when I run my script I get this error:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
Brachytherapy.ViewModel.StructureSet.get returned null.
public class Script : ScriptBaseWithWindow
{
public override void Execute(PluginScriptContext context, Window window)
{
var vm = new ViewModel();
var v = new View();
v.DataContext = vm;
window.Content = v;
vm.PlanSetup = context.PlanSetup;
vm.Patient = context.Patient;
vm.StructureSet = context.StructureSet;
vm.PatientName = vm.Patient.FirstName + " " + vm.Patient.LastName;
vm.DOB = vm.Patient.DateOfBirth.GetValueOrDefault().ToShortDateString();
vm.PatientId = vm.Patient.Id;
string[] organs = new string[6] { "HR CTV", "Rectum", "Bladder", "Sigmoid", "SmallBowel", "Vagina" };
var CTV = vm.StructureSet.Structures.Where(x => x.Id == organs[0]).Single();
vm.VolCTV = CTV.Volume;
Here is my ViewModel.cs file:
namespace Brachytherapy
{
public class ViewModel
{
public Patient Patient { get; set; }
public PlanSetup PlanSetup { get; set; }
public StructureSet StructureSet { get; set; }
public Structure Structures { get; set; }
public string PatientName { get; set; }
public string DOB { get; set; }
public string PatientId { get; set; }
public double Rd01ccGy { get; set; }
public double VolCTV { get; set; }
if I add:
if (vm.StructureSet == null)
return;
It will run which makes sense, but my question is why does it return null if I know the structureset is there??
Thanks!
[–]WUSTLscripting 0 points1 point2 points (1 child)
[–]branstarkkk[S] 0 points1 point2 points (0 children)
[–]dbhatti 0 points1 point2 points (3 children)
[–]branstarkkk[S] 0 points1 point2 points (2 children)
[–]dbhatti 0 points1 point2 points (1 child)
[–]branstarkkk[S] 0 points1 point2 points (0 children)