georeference.org
Subscribe to this thread
Home - Scripting / All posts - Respect escape key, and/or cancel from a dialog, to abandon whole script
woodyplant8 post(s)
#30-Jul-16 15:10

I have a script (the Manifold default Script, which I take to be VBSCRIPT) that does lots of spatial overlays in a loop. Sometimes there is an error, and the spatial overlay dialog is left paused for input. When I press cancel on this dialog, I would like to abandon the whole script. Can I do that?

I note that the MSDN help for VBSCRIPT mentions using WSCRIPT. related methods, but manifold doesnt recognise that..

Likewise, I would like to be able to press <ESC> (or any other key) at any time and abandon the (v long running) script. Is there an equivalent of

ON KEY "ESC" ...exit sub

I notice the windows10 task manager doesnt distinguish the script from the whole Manifold app, otherwise I could haved stopped it from there.

thanks

William

steveFitz

151 post(s)
#01-Aug-16 02:20

William,

Would it be possible to post your code?

There may be a few possibilities but without knowing if the error can be captured it is difficult to say.

There is also the Progress object that may help

'vbscript

Sub Main

 its = 1000

 Call MakeProgress(its)

End Sub

Sub MakeProgress(its)

 set h = Application.History

 Set progressTracker = Application.NewProgress()

 progressTracker.Caption = "waiting..."

 progressTracker.MaxPosition = its

 progressTracker.Position = 1

 progressTracker.Start()

 

 For x = 0 to its -1 

 h.Log("x = " & x + 1 & vbnewline)

 if progressTracker.Update() then

   progressTracker.Position = x

 progressTracker.Text = "still waiting... " & progressTracker.Position

 else

 Application.MessageBox "Progress interupted!""Script"

 progressTracker.Stop()

 Exit Sub

 End if

 Next

 progressTracker.Stop()

End Sub

Steve

woodyplant8 post(s)
#04-Aug-16 11:45

Steve,

Many thanks for your reply. I'll have a go adding your Makeprogress routine, but I guess there may be a simpler solution. Its not only that I want to catch errors- I would like to be able to just cancel in mid flow (without having to press a "carry on" button after each iteration)

thanks

William

this is my script

Sub Main

&these are the various drawing layers that I need to imprint with codes

maxtolayers=6

dim tolayers(7)

tolayers(1)="Africa_name6tmp"

tolayers(2)="Africa_name5tmp"

tolayers(3)="Africa_name4tmp"

tolayers(4)="Africa_name3tmp"

tolayers(5)="Africa_name2tmp"

tolayers(6)="Africa_name1tmp"

&..and these are the from- drawing layers which have the data I want to copy to touching to-layers

maxlayers=25

dim chorlayers(26)

chorlayers(1)="AA"

chorlayers(2)="AM"

chorlayers(3)="AZ"

chorlayers(4)="CA"

chorlayers(5)="GCCON"

chorlayers(6)="GCD"

chorlayers(7)="GCLO"

chorlayers(8)="GCM"

chorlayers(9)="GCO"

chorlayers(10)="GCSW"

chorlayers(11)="GCUG"

chorlayers(12)="GCW"

chorlayers(13)="KH"

chorlayers(14)="KN"

chorlayers(15)="LV"

chorlayers(16)="ME"

chorlayers(17)="NOCLASS"

chorlayers(18)="SA"

chorlayers(19)="SM"

chorlayers(20)="SU"

chorlayers(21)="TP"

chorlayers(22)="LANDTROPAF"

chorlayers(23)="WA"

chorlayers(25)="ZZ"

chorlayers(24)="ZM"

Application.MessageBox "Overlaying areas ", "Chorology overlay"

Document.ComponentSet ("Sepveglayers").Open

Set ui=Application.UserInterface

for ntolayer=1 to maxtolayers

layertx=tolayers(ntolayer)

for nch=1 to maxlayers

ui.InvokeCommand "MapSpatialOverlay"

Application.StatusText="Overlaying "+chorlayers(nch)+" to layer "+layertx

Set dlg=ui.ModalDialog

dlg.ControlSet("ComboBoxSource").Text="[All Objects in "+chorlayers(nch)+"]"

dlg.ControlSet("ComboBoxTarget").Text="[All Objects in "+layertx+"]"

dlg.ControlSet("ComboBoxMethod").Text="Areas to touching areas"

& i tried adding this to give me some route out when it all goes wrong (I have to change the method manually)

if dlg.ControlSet("ComboBoxMethod").Text<> "Areas to touching areas" then exit sub

dlg.Accept

next

next

End Sub

steveFitz

151 post(s)
#05-Aug-16 05:56

William,

I didn't realise that spatial overlays were only done using UI scripting (?). I don't think the Progress object is going to help with separate thread scripts.

See this thread for some elucidation.

Steve

steveFitz

151 post(s)
#05-Aug-16 06:33

There would be a way to replicate the spatial overlay process using SQL and perhaps SQL embedded in a script to iterate through the layers. That sort of SQL is beyond me but I see there is at least one example on the forum.

If this can be done then it should be possible to use the Progress object (and perhaps other methods).

Steve

woodyplant8 post(s)
#05-Aug-16 10:17

Steve,

Many thanks for your consideration of the matter. Im sort of resolved, now Ive seen others apparently havent solved the same basic problem.

Yes, I'm trying to just automate what I normally do with the UI rather than do it in SQL.

I suppose I could add a dialog every loop ("Carry on?") that has a short timeout and the script carries on unless I specifically say don't.

Can anyone point me to a good basic list/reference to the VBscripting methods in Manifold. I looked in scripting samples, but havent found an inputbox with timeout yet. I tried:

a=Application.input("Carry on","",Timeout=1), but it just keeps the input box open.

thanks again,

William

artlembo


2,712 post(s)
#05-Aug-16 14:58

A good way to learn the object model in Manifold is with the Introduction to Scripting in Manifold course here.

It will walk you through how to use the object model in Manifold

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