@Confirm with timer

I often want a message that has been created by @Confirm to disappear after say 3 seconds so that I don't have to muck around dismissing it. That's not one of the normal DOpus commands (at least, I think it's not), but it looks as if it can be done with a script by putting a timer onto a dialogue.

I'm not sure how to do this, however, because I can't work out either the logic or the syntax of the Dialog.SetTimer command.

I'm aiming to write a nice general-purpose function that is an analogue to @Confirm, but has an extra argument for the time for which it is displayed.

1 Like

Jon, I'm out of my depth — throw me an Angel Ring. I have downloaded the clock button, and it works perfectly on my toolbar, but then I'm lost.

  1. I created a simple DOpus.dlg in a test add-in. Then I tried adding just the single line
    var oTimer = oDlg.SetTimer (3000),
    but it throws an 'error at position 3', and:
  • 'A method was called unexpectedly (0x8000ffff)' when placed before oDlg.show,
  • 'Invalid procedure call or argument (0x800a0005)' when placed after oDlg.show.
  1. How does the downloaded button-script go into a script add-in, rather than a button? Specifically, I don't know what to do with the script resources.

  2. Do I need to use Dlg.detach message boxes, or can I do it with simple message boxes, which I would prefer?

  3. I'm not wanting any display of the clock, only to make the dialogue box go away after say 3 or 5 seconds. What is the best URL reference to XML syntax that will allow me to edit the given XML code accordingly, if that is necessary?

This is where one sadly realises that one is, and will remain, an amateur.

https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Scripting/Resources.htm explains how to use resources in a script add-in.

If you post your dialog and code I'll have a look.

Thanks. Jon, I took the Clock script, atttempted to translate it into JScript, then adapted it to an autoclose button (I'll work on the add-in script later). I also made trivial changes in Resources — smaller font and longer box.

function onClick (clickData) {
  var oDlg = DOpus.Dlg
  oDlg.template = "clock"
  oDlg.detach = true
  oDlg.show
  var oTimer = oDlg.SetTimer (1500, "CloseTimer")
  oDlg.Control ("time").label = "This message will disappear in 3 seconds."
  var oMsg = oDlg.GetMsg ()
  var nCount = 0
  while (oMsg && nCount < 4000) {
    var oMsg = oDlg.GetMsg ()
    if (oMsg.event == "timer") {
      oDlg.KillTimer ("CloseTimer")
      oDlg.EndDlg ()
    } // End if
	nCount++
	DOpus.Output ("nCount = " + nCount)
  } // End while	
} // End function

Four problems:

  1. The counter is there because otherwise it doesn't close, and a few instances fill up memory. I don't understand why.

  2. I had to set the timer to 1500 ms — half of 3000 ms — to get it to close in 3000 ms. I don't understand why.

  3. I don't know how to add a title to the box.

  4. The VB Script has ByRef clickData. I don't understand what ByRef means, and I don't know what it's analogue is in JScript.

I've now solved problems 1 and 2 above by ditching the while loop and simplifying the code to:


function OnClick (clickData) {
var oDlg = DOpus.Dlg
oDlg.template = "clock"
oDlg.detach = true
oDlg.show
var oTimer = oDlg.SetTimer (3000, "CloseTimer")
oDlg.Control ("time").label = "Will disappear in 3 seconds."
if (oDlg.GetMsg ().event == "timer") {
oDlg.KillTimer ("CloseTimer")
oDlg.EndDlg ()
} // End if
} // End function


although I don't understand how Control and GetMsg are controlling the flow, so I am not convinced that the code is correct.

I've also managed to get it all into a script add-in, using an argument for the message text, provided op course that the Resources come at the very bottom of the JS file, not just after the add-in function.

  1. is still outstanding because I can't find any list of XML code words for the resources in the DOpus Help files. There are several more that I would like if they are on offer.

  2. is outstanding because I don't know whether ByRef is a VBScript special, or something that has a JScript analogue and should therefore be there.

You don't define the xml resources by hand. There is a dialog editor for making them, built in to the program.

As Leo said, use the dialog editor to edit the dialogs - don't try defining the resource by hand.

You also need to put the while loop back - you need to run a proper message loop, simply handling the first message that comes in will not do what you want.

None of the code you've posted corresponds to the first error you complained about ("error at position 3").

Have you actually looked at the section in the manual on script dialogs? It sounds like you may not have since most if not all of your questions are addressed there. If you're going to try doing scripting you really should at least glance at the docs rather than just trying to muddle through without a clue :slight_smile:

Thanks, jon and leo. OK, I'll stop trying to edit the resource myself. I'll do it in the button version of the script, then copy it over to the add-in.

I did do my best to read all the relevant pages after jon told me to do so, but without a lot of understanding, so I will now make some time and re-read them again very carefully from the top.

I overcame the 'error at position 3' a while ago.

Thanks for your patience. I'll do my absolute best now with this, and hopefully solve it completely.

(By the way, in my previous post, the Forum webpage unhelpfully changed my numerals 3 and 4, which I had typed at the start of my last two paragraphs, to 1 and 2, and indented them, thus confusing everything. This is a really bad case of software dumbing things down.)

Use just about anything other than "3." to start the line and you'll be fine, I think. A number followed by a dot will be turned into an ordered list, which makes the web browser do the counting based on the number of elements in the list.

- 3 Works fine

  • 3 Works fine

3) Also works

  1. Also works

3. Doesn't do what you wanted.

  1. Doesn't do what you wanted.

On the other hand, if the problem was that the list was meant to be uninterrupted but restarted on an item, then it means you had a new paragraph inside one of the items and did not indent it to specify that it was still part of the list and not something that came after the list. For example:


1. Item One

    Which also has another paragraph after it, that's still part of the list.

1. Item Two

    This has another paragraph as well.

1. Item Three

1. Item Four
  1. Item One

    Which also has another paragraph after it, that's still part of the list.

  2. Item Two

    This has another paragraph as well.

  3. Item Three

  4. Item Four

The nice thing about it is you can have a large number of items in a list and then insert or remove items without having to manually renumber the entire thing.

You could send feedback to the inventors of markdown / markup, or the Discourse authors but I think the ship has sailed on that kind of syntax as it has been in use in a lot of places for many years. It's just a case of learning how it works.

Jon and leo, I've read and read, as instructed, and the best that I can come up with is this — not pretty, but it doesn't seem to break anything or fill memory. If you declare it safe, I'll post a script addin with a couple of useful commands involving autoclosing message boxes.

function OnClick (clickData) {
  var oDlg = DOpus.Dlg
  oDlg.title = "Notification"
  oDlg.template = "timernotify"
  oDlg.detach = true
  oDlg.show
  var oTimer = oDlg.SetTimer (2000, "TimerNotify")
  oDlg.Control ("time").label = "This will disappear in 2000ms"
  do {var oMsg = oDlg.GetMsg ()
    var bClose = true 
  } while (oMsg && !bClose) // End while
} // End function
<resources>
	<resource name="timernotify" type="dialog">
		<dialog fontsize="9" height="50" lang="english" resize="yes" standard_buttons="ok" width="188">
			<control halign="left" height="25" name="time" type="static" width="173" x="6" y="6" />
		</dialog>
	</resource>
</resources>

That doesn't look like it should work. You're setting bClose after every message, not just in reaction to messages telling you the timer happened. Messages are sent to the dialog for all kinds of reasons. Look back at the example Jon linked to and you'll see it checks the message is a timer message.

bClose should also be a variable declared outside the loop body if you want to test it as a condition of the do...while loop.

As a more minor thing, it is best to put ; at the ends of statements in jscript/JavaScript, or things will go wrong in strange ways. Making it guess where to put them is unreliable. (It was a bad idea to make them appear optional as they aren't really, but that's how the language was designed.)

An example time in js/vbs/dopus script would be much appreciated. Thanks.