I’m creating a set of WPF dialog nodes in C# for Dynamo and have a couple of related questions:
(1) Is there a way of detecting whether Dynamo is running in Revit, Sandbox or Studio mode?
(2) Why are threads treated differently in Dynamo Sandbox and Revit?
Details below:
In Sandbox mode,my node needs to call the dialog on a separate thread otherwise I get the following message:
I have therefore used the following code to call it which works fine:
DialogData myData = new DialogData() { SplashTitle = SplashTitle, SplashText = SplashText };
myData.InputList = myList;
//myData.openDialog();
ThreadStart dele = new ThreadStart(myData.openDialog);
Thread t = new Thread(dele);
t.SetApartmentState(ApartmentState.STA);
t.Start();
MessageBox.Show(“this far”);
t.Join();
However, if I run this in Dynamo Revit it crashes, but if I open the Dialog on the main thread it works (i.e. the approach that crashes in Dynamo Sandbox):
DialogData myData = new DialogData() { SplashTitle = SplashTitle, SplashText = SplashText };
myData.InputList = myList;
myData.openDialog();
For this reason, I need my node to detect how Dynamo is running so that it can modify its behaviour to suit.
Thanks!