Hi scripters,
I’m trying to use the WScript.Timeout function to terminate the execution of a script after a certain time (in sec) but I cant figure out how to get an instance of the Wscript object.
Can someone point me in the right direction?
you could create and use the WScript object in a RhinoScript like this:
Option Explicit
Call Main()
Sub Main()
Dim objShell
Set objShell = CreateObject("WScript.Shell")
If Not IsObject(objShell) Then
Rhino.Print "Error getting WScript"
Exit Sub
End If
objShell.Run "Explorer.exe", 0, vbFalse
Set objShell = Nothing
End Sub
but you can use the WScript.Timeout function only in a *.vbs script as far as i understand. To make a RhinoScript stop after a certain time you could use a Do / Loop and check the running time. eg.:
Option Explicit
Call Main()
Sub Main()
Dim t, timeout_seconds, elapsed
t = Timer
timeout_seconds = 2
Do
' do something here
' stop the loop
elapsed = timer - t
If elapsed > timeout_seconds Then Exit Do
Loop
Rhino.Print "Loop stopped after " & elapsed & " seconds"
End Sub
@stevebaer formating of Python and RhinoScript code is still broken, therefore i´ve attached the second script as file below.
Hi Clement,
Thanks for your answer. I guess what I want doesnt work in Rhino script… I want a timeout of a GetString. The user has to provide a string and the script should continue after a certain time (in sec) if nothing is entered.
Don’t ask me what for… its a little funny thing, so nothin really needed for work.
i guess you could do this in python using an input box in a WinForm dialog and set up a timeout for the whole dialog. In RhinoScript there is no WinForm access but it could be done similar using a window.Close() call in a Rhino.HtmlBox.
For auto closing input string, i´ve quickly hacked below together, it just closes and prints “empty” after 5 seconds if nothing has been entered, otherwise it prints what has been entered.
There are much better ways to do it for shure, eg. cancel the timout if something is currently entered or cancel the timeout and close if ENTER has been pressed after entering something…
Yeah… im still programming in rhinoscript. Maybe its about time to change to python once and for all.
What was stopping me up to now is that there is no script compiler for python…