Hi
When i used Opossum solver i needed to detect start/stop buttons clicks
This is a way, if someone want recreate it with c# which is better and more stable with ExpireSolution(True)
import System
class MyViewEventInfo:
def __init__(self):
#opened forms
forms = System.Windows.Forms.Application.OpenForms
#find opened forms and choose opossum window
windows = []
for i,n in enumerate(forms):
if n.Text == '(M)opossum':
windows.append(n)
if windows:
window = windows[0]
#find tabs in opossum window
ctrls = window.Controls
for i,n in enumerate(ctrls):
if type(n) == System.Windows.Forms.TabControl:
tab = n
#find tab in opossum window called Run Optimization
tabs = []
for i,n in enumerate(tab.Controls):
tabs.append(n)
tabs[0] #the first tab index 0 Optimize!
#find groups in the first tab
for i,n in enumerate(tabs[0].Controls):
if n.Text == 'Run Optimization':
group = n
#find buttons in Run Optimization group
buttons = []
for i,n in enumerate(group.Controls):
buttons.append(n)
buttons[0].Click += self.OnClick
buttons[1].Click += self.OnClick
self.start = buttons[0]
self.stop = buttons[1]
if windows:
self.check = self.start.Enabled
else:
self.check = None
def OnClick(self, sender, e):
ghenv.Component.ExpireSolution(True)
print MyViewEventInfo().check
a = MyViewEventInfo().check #output
And this code with c# to change DataDam delay time without limits
private void RunScript(int n)
TimeSpan time = new TimeSpan(0, 0, n);
GH_Document ghdoc = owner.OnPingDocument();
if (ghdoc == null)
{
return;
}
foreach (IGH_DocumentObject obj in ghdoc.Objects)
{
if (obj.NickName == "Dam")
{
Grasshopper.Kernel.Components.GH_DataDamComponent datadam = obj as Grasshopper.Kernel.Components.GH_DataDamComponent;
if (datadam.Params.Input[0].NickName == "Input")
datadam.Delay = time;
}
}