Cancel Ruby script
-
From what I have read in other topics at this moment it is impossible to cancel a running script?
Is this correct?
Cause that means that each script that does a large action has to be killed by ending the windows process?Thx
-
Yup, that is still true.
-
Nope, not exactly true. It MAY be possible, but I keep getting BugSplats. If I can fix that, I'll let you know.
I have been trying to use the timout.rb file that comes with the Ruby Language. It can stop a running script:
require 'timeout' timeout(5) { long_running_script() }
But it would be nice to also use model.abort_operation
Sketchup.start_operation "Operation" begin timeout(5) { long_running_script() } rescue Sketchup.active_model.abort_operation UI.messagbox("Operation Aborted") else Sketchup.active_model.commit_operation end
If you try this, be aware that it may bugsplat.
-
ok, thank you.
From what i can see now, i have a function that automatically plays a visualization in time. On some occasions, when i keep the mouse above the stop button, i get the tooltip and then i can hit that button.
Maybe if you put in a 'sleep' for let's say a second after a certain amount of time then the user can click the button.
I'll test and let you know. Could be a half solution till Jim gets his marvelous script out -
@jim said:
but I keep getting BugSplats.
Hehehe, story of my Ruby life!
Seriously though, good luck to Jim!
Chris
-
Jim, i did not see the script previously.
Doesn't the timeout function require an amount of seconds?
So if the script is not finished within this amount of seconds it is cancelled automatically? -
Yes, that is right. The time is in seconds, and the script will stop if it time out.
Do have a particular script in mind?
-
@jim said:
Yes, that is right. The time is in seconds, and the script will stop if it time out.
Do have a particular script in mind?
Not specific yet.
The global idea is that you can just hit a button (in a webdialog or in Sketchup itself) that immediately stops the ongoing script (like you said probably with the start and end_operation method)
If I understand your idea correctly, you will use an external button that will trigger the timeout, that one will countdown from 5 seconds and then execute the end_operation function?With your idea i did some tests. The problem is i can't hit anything, not in a webdialog, nor in sketchup itself.
I have another function that is build like this:execute script/start a timer
the timer checks each 2 seconds if the script has been executed
if so: execute the script again with different parametres
now like that i sometimes do have the possibility to hit a stop button i created (after each loop).Here is the script:
def COMMON.play_timeintervallist #Automatically plays the whole Time Interval list # set the play status to 1 $playing=1 #go forth one milestone to initiate the movie COMMON.milestones_forward #execute the milestones_forward command each 2 seconds $playertimer=UI.start_timer(2, true) { # first check if the previous milestones forward has finished, if so, go to the next milestone, continue counting till it is finished. if $milestones_forward_exe==1 COMMON.milestones_forward end #stop the timer when $selected_delphidate= last date in milestoneslist if $selected_delphidate==$milestones[-1][1] COMMON.stop_timeintervallist end } end #-------------------------------------------------------------------------------------------- def COMMON.stop_timeintervallist #Stops the Time Interval list play UI.stop_timer $playertimer $playing=0 end
and a second part:
def COMMON.milestones_forward #Milestone navigation forward #not yet executed (used in COMMON.play_timeintervallist) $milestones_forward_exe=0 #if the milestoneslist had not been generated yet if $milestones == nil COMMON.create_timeintervallist end #get the current date c_date=$selected_delphidate #get the next milestone #loop through the milestones list and see what date is higher then c_date i=0 while i < $milestones.size #split milestones[i] in 2 dates _normaldate=$milestones[i][0] _delphidate=$milestones[i][1] #if c_date is smaller then a milestone delphidate then this milestone is the milestone to be shown if c_date < _delphidate $selected_date = _normaldate $selected_delphidate = _delphidate CreateConnection.call ShowToDate.call($selected_delphidate) DestroyConnection.call #flag that it is initiated from milestone selection $datefrommilestone=1 SHOW.showdate break end i+=1 end #executed (used in COMMON.play_timeintervallist) $milestones_forward_exe=1 end
maybe it is possible to use something simular?
Advertisement