C# automatic double-click on Galapagos or by GUID + HumanUi (optional)

Hello everyone.

This discussion follows on from the previous ones. I’ve made a lot of progress on my double-click automation script.

Old discussions referring to my code (which have since been resolved, see the code attached to this message):

I can double-click on Galapagos, for example, if it’s visible in the canvas.
If it’s not visible, I can zoom in and generate a double-click.

→ What I want is that if the zoom has been done, after the double-click, it returns to the initial view on the canvas.
I have successfully reset the view on the canvas, but unfortunately the double click occurs after the initial view has been restored.

The video below explains it all :

yet the order of the tasks is well defined, I’ve tried adding a thread.sleep but it doesn’t work either :

if (activate)
{
ZoomToComponentIfNotVisible(ghObject);
PerformMouseDoubleClick(new System.Drawing.Point((int) objectBounds.Left, (int) objectBounds.Top), objectBounds.Size);
Thread.Sleep(1000);
ResetViewportToOriginal();

  }

I’d like to use the System.Threading.Tasks command but I can’t find it.
Does anyone have an idea? or have another function in mind? to ensure that my tasks run in the right order?

Thanks a lot

double click Galapagos.gh (10.1 KB)

1 Like

I found the function I needed :

if (activate)
{
ZoomToComponentIfNotVisible(component);
PerformMouseDoubleClickAsync(new System.Drawing.Point((int) componentBounds.Left, (int) componentBounds.Top), componentBounds.Size)
.ContinueWith(t =>
{
System.Threading.Thread.Sleep(1000);
ResetViewportToOriginal();
});
}

with :

private Task PerformMouseDoubleClickAsync(System.Drawing.Point position, System.Drawing.SizeF size)
{
var tcs = new TaskCompletionSource();
var p = Grasshopper.Instances.ActiveCanvas.Viewport.ProjectPoint(position);
var f = Grasshopper.Instances.ActiveCanvas.Viewport.ProjectPoint(new System.Drawing.PointF(size.Width + position.X, size.Height + position.Y));
var r = Grasshopper.Instances.DocumentEditor.ActiveControl.RectangleToScreen(new System.Drawing.Rectangle());
var d = new System.Drawing.Point((int) (r.Left + (p.X + f.X) / 2), (int) (r.Top + (p.Y + f.Y) / 2));

Cursor.Position = d;

// Perform a double-click
mouse_event(0x02, 0, 0, 0, UIntPtr.Zero); // Perform MOUSEEVENTF_LEFTDOWN
mouse_event(0x04, 0, 0, 0, UIntPtr.Zero); // Perform MOUSEEVENTF_LEFTUP
mouse_event(0x02, 0, 0, 0, UIntPtr.Zero); // Perform MOUSEEVENTF_LEFTDOWN
mouse_event(0x04, 0, 0, 0, UIntPtr.Zero); // Perform MOUSEEVENTF_LEFTUP

tcs.SetResult(null);

return tcs.Task;

The code below automatically double-clicks on a Galapagos component.

If it is visible, or if it is not visible in the canvas

If it is not visible, the code zooms in on Galapagos, performs the double click and then returns to the previous canvas view.

double click GalapagosV3.gh (12.0 KB)

Now I just need to find out how to do this operation if the canvas is not visible either.
Example using HumanUI with the canvas closed :slight_smile:

Update

In the code below, I’ve added the ability to use HumanUi with a button that triggers a double-click on the canvas.
On a Galapagos component or on a component defined by a GUID.

This call can be made on a minimised canvas, in which case the code will maximise it by looking for where the component is to perform the double click.

I would have liked to re-minimise the canvas after opening the component, but for Galapagos for example this is not possible, minimising the canvas window also minimises Galapagos…

double click Galapagos or with GUID + HumanUi.gh (13.7 KB)

1 Like