Subscribe to this thread
Home - General / All posts - UI scripting
mghasemi
92 post(s)
#24-Feb-17 16:24

Hello

I have the following code within my script. It's very unstable. Sometimes works fine sometimes gives an error and stops at ".Item("ComboBoxX").Text = "X"" with this error : "Index out of range, Line..."

I added Delay but it did not help,

Is there a replacement or a modified version which is stable?

Thanks

Delay 1, True

Set UI = Application.UserInterface

UI.InvokeCommand "ViewProjectPasteAsDrawing", "Pane:Project"

Set Dlg = UI.ModalDialog

Delay 1, True

With Dlg.ControlSet

.Item("ComboBoxX").Text = "X"

.Item("ComboBoxY").Text = "Y"

.Item("CheckBoxLatitudeLongitudeCoordinates").Checked = False

.Item("ButtonOK").Push

End With

adamw


7,159 post(s)
#24-Feb-17 16:40

Try putting the second call to Delay *before* taking UI.ModalDialog. (You don't need the first call to Delay.)

mghasemi
92 post(s)
#24-Feb-17 19:04

It did not work...

firsttube


1,427 post(s)
#24-Feb-17 17:08

See this thread: http://www.georeference.org/forum/t131635.9

I had found that turning off certain background programs like Adobe Updater or TeamViewer solved the issue. Could be coincidence, I don't know. It seemed like something was taking the focus away from Manifold...


"The blessing in life is finding the torture you are comfortable with." - Jerry Seinfeld, 6/26/2013

mghasemi
92 post(s)
#24-Feb-17 19:19

I want to use

Do

Loop until ui.ModalDialog.Caption = "XXXX"

How do I know what is caption? For example above I used "Paste as Drawing" but did not work

tjhb

7,457 post(s)
online
#24-Feb-17 19:34

Whatever is shown in the title bar of the dialog when you open it manually. Exactly, including case.

mghasemi
92 post(s)
#24-Feb-17 19:54

Thanks.

I used "Paste As Drawing" which is exactly what shown on manual dialog.

However, it did not work.

I tried manually printing ui.ModalDialog.Caption and it was empty after UI.InvokeCommand "ViewProjectPasteAsDrawing", "Pane:Project"

So even with loop, it did not change and was empty.

tjhb

7,457 post(s)
online
#24-Feb-17 19:57

Please post your whole script so we can get it working.

Also, rather than saying that something does not work, it's usually much mire helpful to say what does happen--what you observe.

mghasemi
92 post(s)
#24-Feb-17 20:16

Thank you.

When I used the Do Loop until ui.ModalDialog.Caption ="Paste as Drawing" nothing happened. Basically the condition never met. Although the dialog opened had the exact caption, it seems the loop condition was never met.

When I used Delay instead of this Do loop , it just gave the index out of range error

The entire code is very long the related part is this:

'Make Well Drawings

set Tbl=Document.ComponentSet("WellLocations_Table")

If Document.ComponentSet.ItemByName(Tbl.Name & " 2")<> -1 Then ' It does exist

Document.ComponentSet.Remove(Tbl.Name & " 2")

End If

Tbl.Copy False

Set UI = Application.UserInterface

UI.InvokeCommand "ViewProjectPasteAsDrawing", "Pane:Project"

Do ' Nothing

Loop Until UI.ModalDialog.Caption = "Paste As Drawing"

Set Dlg = UI.ModalDialog

With Dlg.ControlSet

   .Item("ComboBoxX").Text = "X"

   .Item("ComboBoxY").Text = "Y"

   .Item("CheckBoxLatitudeLongitudeCoordinates").Checked = False

   .Item("ButtonOK").Push

End With

tjhb

7,457 post(s)
online
#24-Feb-17 20:37

And the Delay subroutine/function? What are you using for that, when you are?

But the main issue is that you're not waiting for a modal dialog to show before trying to access its properties.

Easily fixed.

mghasemi
92 post(s)
#24-Feb-17 20:48

Private Sub Delay(s, doLog)

' The Shell.Sleep method is not available within the Manifold context

' so we use an "active" loop instead (occupies a core)

Dim i

Dim start

'

For i = 1 To s

start = Now

Do ' Nothing

Loop Until DateDiff("s", start, Now) >= 1

' More robust than Timer function

' if operation spans midnight

If doLog Then Application.History.Log ".", True

Next

If doLog Then Application.History.Log vbCrLf, True

End Sub

mghasemi
92 post(s)
#24-Feb-17 20:50

Could you please tell me how to fix it?

I used the code below for display but it did not have any outcome.

Do

Loop until ui.DisplaysModalDialog

firsttube


1,427 post(s)
#24-Feb-17 20:58

Have you tried closing all unnecessary background programs running on your system before running your script? I was having the same issues until I turned off the Adobe Acrobat updater and TeamViewer applications that were running in my system tray. My UI script ran correctly once I did that. Could be coincidence, but I thought maybe these programs were somehow interfering with the dialogs in Manifold.


"The blessing in life is finding the torture you are comfortable with." - Jerry Seinfeld, 6/26/2013

mghasemi
92 post(s)
#24-Feb-17 21:31

I just rebooted my PC. but the same errors as before....

tjhb

7,457 post(s)
online
#24-Feb-17 21:01

Sure, back soon. I should have said.

tjhb

7,457 post(s)
online
#24-Feb-17 21:18

Try this.

Here is Main, adjusted:

Sub Main

    ' ...

    Set Tbl = Document.ComponentSet("WellLocations_Table")

    ' ...

    Tbl.Copy False

    Application.UserInterface.InvokeCommand "ViewProjectPasteAsDrawing""Pane:Project"

    Set Dlg = GetUIDialog("Paste As Drawing", 5)

    With Dlg.ControlSet

    ' ...

End Sub

Here is a function to wait for a modal dialog with the specified caption.

Function GetUIDialog(caption, timeout)

    ' Wait for a modal dialog with the specified caption to show,

    ' subject to an overall timeout in seconds 

    ' (-> log and throw error)

    Dim ui

    Dim start

    Dim dlg

    Set ui = Application.UserInterface

    start = Now

    ' Wait for some modal dialog to show

    Do

        If DateDiff("s", start, Now) >= timeout Then

            Application.History.Log "Timeout waiting for a modal dialog (" _

                & CStr(DateDiff("s", start, Now)) & " sec)" & vbCrLf, _

                True

            Err.Raise 17 ' Can't perform requested operation

            'Exit Do ' not required

        End If

    Loop Until ui.DisplaysModalDialog 

    ' Wait for the current modal dialog to show the expected caption

    Set dlg = ui.ModalDialog

    Do

        If DateDiff("s", start, Now) >= timeout Then

            Application.History.Log "Timeout waiting for " & Chr(34) & caption & Chr(34) & " dialog (" _

                & CStr(DateDiff("s", start, Now)) & " sec)" & vbCrLf, _

                True

            Err.Raise 17 ' Can't perform requested operation

            'Exit Do ' not required

        End If

    Loop Until dlg.Caption = caption

    Set GetUIDialog = dlg

End Function

The function is also attached.

(Slight adjustment to script originally posted here.)

Attachments:
GetUiDialog.txt

mghasemi
92 post(s)
#24-Feb-17 21:44

Thanks a lot.

I used your fuction and it showed the following message hardcoded into your function.

tjhb

7,457 post(s)
online
#24-Feb-17 21:49

Then that is a mystery!

At this stage I would follow up firsttube's hunch and lead. Try listing all of your startup and background processes.

mghasemi
92 post(s)
#24-Feb-17 22:03

Thanks for your help.

I did reboot my PC and nothing is open except Manifold

tjhb

7,457 post(s)
online
#24-Feb-17 22:11

What operating system?

mghasemi
92 post(s)
#24-Feb-17 22:46

Windows 7

Manifold 8

mghasemi
92 post(s)
#24-Feb-17 23:27

So, yes it open dialog with the title "Paste As Drawing"

but it looks like the dlg.caption does not match this even if you wait for a long time.

mghasemi
92 post(s)
#24-Feb-17 23:36

I tried priting dlg.caption (please see blow) it return empty string

tjhb

7,457 post(s)
online
#25-Feb-17 02:26

Yes. Well, it could be something else in the rest of the script, but that seems unlikely.

You could perhaps check that by writing a new script, a very short one, that odes nothing more than copy and paste this particular table as a drawing.

By the way I did test with a dummy table on my system before posting the code. No problem here: a minimal script (using the GetUIDialog function above) works just as expected.

I expect that firsttube is right, there is something else on your system that is interfering with Manifold's communication between one of its threads and another.

In other words, that this is not a Manifold problem, but a problem with a third party service or background process. A fairly obtrusive or aggressive one, though not necessarily malicious in any way.

To see what else is running automatically when you boot Windows--and when "nothing is open except Manifold"--launch the System Configuration app. One way to do that is to press Windows key+R, then type in msconfig.exe and hit OK.

Now have a look in the Startup tab. You could post a screenshot of the list if you like (or more than one if really long).

You could also open up Task Manager and look in the Processes tab, sorting the list on Image Name. This list is longer.

Neither list is exhaustive, since there are also services and scheduled tasks, but they are a start.

adamw


7,159 post(s)
#25-Feb-17 06:03

If the issue is related to DLL hooks (it might), what could help is to check the script in both 32-bit and 64-bit modes. The hooks are frequently different and so the script might work in one mode but not the other.

jockeryl
170 post(s)
#28-Feb-17 02:44

Out of curiosity, what alternative solutions are there to do this on a server without a UI command?

Application.UserInterface.InvokeCommand "ViewProjectPasteAsDrawing", "Pane:Project"

If I understand it, the copy&paste of drawing actually copies the Geom objects and paste append to the target drawing.

Are there alternatives in the scripting API or as SQL command running under the Manifold Runtime?

adamw


7,159 post(s)
#28-Feb-17 08:18

Well, yes, you can do what Paste As Drawing does in Manifold 8 via a script or a query.

I imagine a query would do CREATE DRAWING, then INSERT selecting data from the source table. A script would do Document.NewDrawing, then insert objects into that drawing.

Some operations that can be done in Manifold 8 via the UI are hard to do via scripts or queries, but that's not one of them. (We reverted the situation in Radian, in Radian we add functionality to scripts / queries first, the UI accesses it from there.)

adamw


7,159 post(s)
#25-Feb-17 06:01

I can not reproduce what you are seeing.

I made several minor adjustments to the script you used (replaced Delay with an infinite loop that can be easily exited via user action if desired, commented out a call to Push to let the dialog stay on screen so we can see whether the control values changed, etc), see attached MAP file.

On Manifold 8.0.29 (latest released):

Open the attached MAP file. Open Script. In the Project pane, right click T and select Copy, to put something into the clipboard (else the Paste As Drawing command is going to be disabled). In the main menu, select Script - Run to run the script.

You should see the Paste As Drawing dialog, the X combo should be set to Y (as the script specified, just to show that it can change control values from the defaults), the Y combo should be set to X, the 'Latitude / longitude coordinates' checkbox should be checked.

What happens on your system?

Attachments:
test-ui-script.map

mghasemi
92 post(s)
#28-Feb-17 00:05

Thank you all for your help. Really really appreciate it.

Yes, the problem was not manifold.

I had another program running on background ("Ultramon") which facilitated 2 monitor handling.

Once I closed that application, no more issues.

firsttube


1,427 post(s)
#28-Feb-17 13:45

This is actually good news. I had always suspected a background program interference-type problem here. For me it was Adobe Acrobat updater and/or TeamViewer.


"The blessing in life is finding the torture you are comfortable with." - Jerry Seinfeld, 6/26/2013

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