Subscribe to this thread
Home - General / All posts - Trying to wait for a process to finish
djmcbell10 post(s)
#04-Sep-18 07:12

Hi all - newbie here. I've inherited a load of projects from predecessors and in my current one, I'm trying to paste a load of contours in as a surface before carrying on with various other operations.

The way that it has been done is to paste as a surface using the UI (this is Manifold 8). C# code is:

UserInterface ui = (UserInterface)app.UserInterface;

  ui.Panes["Project"].ControlSet["TreeViewComponents"].Text = "Contours_50cm 2";

  ui.InvokeCommand("ViewProjectCopy""pane:Project");

  ui.InvokeCommand("ViewProjectPasteAsSurface""pane:Project");

  UserInterfaceDialog dlg = (UserInterfaceDialog)ui.ModalDialog;

 UserInterfaceControlSet controlset = (UserInterfaceControlSet)dlg.ControlSet;

  dlg.ControlSet["ComboBoxHeight"].Text = "Altitude";

 dlg.ControlSet["TextBoxPixelSizeX"].Text = "10";

 dlg.ControlSet["TextBoxPixelSizeY"].Text = "10";

 dlg.ControlSet["ComboBoxMethod"].Text = "Triangulation adjusted for contours";

 dlg.Accept();

//+---------------------------------------------

 app.MessageBox("Please wait for the copy to catch up. The loader will resume shortly.",null);

 delay(100); //this was originally 5, changed to allow stuff to catch up

 comps.Remove(theDrawing);

Then we carry on as usual (with the comps.Remove(theDrawing); line).

Now, the drawing that we're copying and pasting in as a surface is pretty big. It's taken me something like 8 minutes and it still hasn't done it. Got half-way though... time isn't really a factor. However, the version left by my predecessor just used delay(5); to try to get it to catch up, which was causing the function to get ahead of itself on larger contours and not process them. I increased it to 100 as a bit of a generous catch-all.

However, the new contours are a lot more detailed. A delay of 100 isn't going to cut it - nowhere near. Heck, I don't know what will. Which is why I'd prefer it to wait until the paste operation has finished and then continue.

As an aside, after about 8 minutes on the paste as surface, Manifold throws up an Unknown Error. Don't know why, but I guess one thing at a time.

tjhb

8,217 post(s)
online
#04-Sep-18 08:34

Usually, delays and tests required after individual UserInterface dialog operations.

Here they would be especially important after invoking ViewProjectCopy--since this operation takes substantial time with significant data--and again after invoking ViewProjectPasteAsSurface to ensure that dialog controls are populated and ready to be set; and lastly before Accept().

I don't think just increasing the delay after Accept() is going to work.

UI scripting can be tricky! And this is one of the trickiest operations to get right (though it can be done).

Now, is there a reason you must use Manifold 8, or can you take advantage of the much improved infrastructure in Manifold 9?

tjhb

8,217 post(s)
online
#04-Sep-18 09:26

This might help. May be unnecessary (or may not).

Dimitri


4,980 post(s)
#04-Sep-18 13:44

Second that, about using 9 if possible. Use the free Viewer, import the contours drawing and use one of the new Interpolate templates to create a surface. Have to believe it would be faster than 8.

KlausDE

6,204 post(s)
#04-Sep-18 08:36

oops, sorry you wait for finishing, not for the start of the thread.

[http://www.georeference.org/forum/t136754.4#136758]

You could check for the expected number of components indicating a successful import.

tjhb

8,217 post(s)
online
#04-Sep-18 08:55

Klaus, note that at 8 minutes the result is said to be both "halfway through" and "unknown error".

I suspect that our instincts are right.

KlausDE

6,204 post(s)
#04-Sep-18 09:40

How long does a manual copy paste take?

Could it be that there is a second dialog asking for an extended surface that the process never catches?

adamw

8,061 post(s)
#04-Sep-18 16:30

I'd first try doing the operation interactively to make sure it completes. If the operation fails from the UI - whether with an "Unknown error" or with something else - it will fail from the script as well. Maybe you have to adjust the parameters, ie, maybe the pixel size above is too small and 8 bails out due to image size.

Once you are sure you can get the operation to complete, you can adjust the script to wait until the operation completes instead of doing a blind Delay(x) - you can do this by running an infinite loop (plus timeout perhaps) and checking the caption of the current modal dialog, see this thread for some discussion and examples.

If 8 won't be able to process the amount of data you throw at it, try 9 (can quickly check whether you will be able to do what you want with Viewer, which is free). 9 can process much bigger data than 8 can and it does so faster, see, for example, the numbers in this post.

djmcbell10 post(s)
#05-Sep-18 02:19

Firstly, thanks everyone for replying. I can barely find anything on Manifold, and it's great to have such a welcoming and helpful community (and so quick to reply too!).

This was the avenue I went down - checking captions of the dialog boxes. I couldn't really get access to clipboard data easily, and we probably can update to v9 but there are lots and lots of processes hooking into Manifold that I don't want to risk the stability of our system.

The code I've used is:

//+----------------------------------------------

  UserInterface ui = (UserInterface)app.UserInterface;

  ui.Panes["Project"].ControlSet["TreeViewComponents"].Text = "Contours_50cm 2";

  ui.InvokeCommand("ViewProjectCopy""pane:Project");

  ui.InvokeCommand("ViewProjectPasteAsSurface""pane:Project");

  UserInterfaceDialog dlg = (UserInterfaceDialog)ui.ModalDialog;

 UserInterfaceControlSet controlset = (UserInterfaceControlSet)dlg.ControlSet;

  dlg.ControlSet["ComboBoxHeight"].Text = "Altitude";

 dlg.ControlSet["TextBoxPixelSizeX"].Text = "2";

 dlg.ControlSet["TextBoxPixelSizeY"].Text = "2";

 dlg.ControlSet["ComboBoxMethod"].Text = "Triangulation adjusted for contours";

 dlg.Accept();

//+---------------------------------------------

 app.MessageBox("Please wait for the copy to catch up. The loader will resume shortly.",null);

 delay(25); //this was originally 5, changed to allow stuff to catch up

 int Proceed = 0;

 //if we can find it, loop, else exit loop

 while(Proceed==0)

 {

 if((string)ui.ModalDialog.Caption!="Paste As Surface"){Proceed=1;}

 }

 comps.Remove(theDrawing);

Now, when I tried it locally it was working with no issues, so the Unknown Error must have just been the process going forward (as a lot of stuff is happening to the surface whilst the copy was still going on - it was being fired prematurely in this case and the paste wasn't completing in time). Decided to improve the TextBoxPixelSizeX and Y as otherwise - what's the point in having improved contours? Takes a good deal of time (for my quick trial, about 30 minutes - compared to the 2 that it was before, but that was with much more primitive contour data and using a TextBoxPixelSizeX/Y of 10).

But yep, the above will keep checking and looping if a box entitled "Paste As Surface" is displayed and has the focus. I left the messagebox and delay there (though reduced the delay to 25) so we ensured the "Paste As Surface" box appeared.

I know it's not exactly future-proof or fool-proof but it'll do for now - it's only really going to be me or my boss who will be running this method.

Thanks again all!

Manifold User Community Use Agreement Copyright (C) 2007-2017 Manifold Software Limited. All rights reserved.