matteoluigi Posted December 14, 2020 Share Posted December 14, 2020 Hi, does there exist a command (both in Vectorscript and Python) for immediately interrupt a script in both python and Vectorscript? I actually am using the foreach-command quite often. There it's quite difficult interrupting with a dialogue with an abort button. Unfortunately "Ctrl-C", "Esc"... don't work. the only working alternative actually is forcing Vectorworks to close completely. Thanks for your help! 1 Quote Link to comment
Pat Stanford Posted December 14, 2020 Share Posted December 14, 2020 The standard on Mac is Command-. (period). But if you loop is very small it is likely that you will never read the keyboard until the script ends. Sorry. I had to do the Force Quit option on a script yesterday. :-( 1 Quote Link to comment
Sam Jones Posted December 14, 2020 Share Posted December 14, 2020 It's always worth a try, but command-period only works about 10% of the time for me. 1 Quote Link to comment
matteoluigi Posted December 14, 2020 Author Share Posted December 14, 2020 @Pat Stanforddoes ist also work, Wheel I‘m stuck in an AlrtDialog? however, worth a try is worth a try 😉 Quote Link to comment
Pat Stanford Posted December 14, 2020 Share Posted December 14, 2020 I think Command-Period in a dialog box is effectively a shortcut for the Cancel button, so it may work, but if you can't click the cancel button I don't have a lot of hope. 1 Quote Link to comment
matteoluigi Posted December 15, 2020 Author Share Posted December 15, 2020 11 hours ago, Pat Stanford said: if you can't click the cancel button I don't have a lot of hope. at least there's a task manager/activity manager on any computer for that case ;-). But, seriously, how can I implement a dialogue with an abort-button in a foreach-loop which cycles through an undefined number of objects? In a for or while loop I can just use an AlertQuestion which returns me the value for escaping the loop, when I press the abort button. But in a foreach-loop? Quote Link to comment
Pat Stanford Posted December 15, 2020 Share Posted December 15, 2020 Add a line in your loop to check for user input and break out of the loop if you get it. Something like. Repeat Repeat Begin {Your loop code here} B1:=((Keydown=113) & Option); {B1 = True if Option Q Pressed} End; Until ((Condition that ends your loop) | B1); This gives VW an excuse to look for keypresses during the loop and should make it breakable as well as manually quitable. Quote Link to comment
Sam Jones Posted December 15, 2020 Share Posted December 15, 2020 I can't check right now, but can you force a ForEachObject() routine to both check the keydown and not go on to the next object? I would think it would go to the next object and check the keydown again. I don't see a way to drop to the last object that meets the conditions in the criteria and then out of the loop. I love ForEach... loops, but I don't see a way to end them early. Of course, I haven't tried the dreaded "GOTO" statement, but that might work after a button down check in the procedure called by the ForEach call. Quote Link to comment
matteoluigi Posted December 16, 2020 Author Share Posted December 16, 2020 13 hours ago, Sam Jones said: I haven't tried the dreaded "GOTO" i didn't dare to use it in fact ;D (also it was one of my favorite commands in GW Basic decades ago 😆) But, good ideas!!! Quote Link to comment
matteoluigi Posted December 16, 2020 Author Share Posted December 16, 2020 @Pat Stanford @Sam Jones thanks for you ideas!!! 🙂 Quote Link to comment
matteoluigi Posted December 16, 2020 Author Share Posted December 16, 2020 MullinRJ writes: Quote You can use GOTO , which causes the execution to jump to the label. GOTO will not jump out of nested procedures, so you'll have to have a and a GOTO at each level to jump to the end of that level when some condition is TRUE. would mean, that there is no exit but "command-." from a foreach-loop. However, really good ideas! https://forum.vectorworks.net/index.php?/topic/44637-abort-script-upon-actionvariable/ Quote Link to comment
JBenghiat Posted December 16, 2020 Share Posted December 16, 2020 Particularly if you're doing some experimentation and testing, you can write in a fail-safe counter to break out of while/do loops: while notFound and safeCount < 10000 ... safeCount += 1 That doesn't really help with ForEachObject(), though, as the loop is internal to the command. FEOInLayer and FEOInList do have return, values, however, so you can escape out of them if you counter gets too high. If this is for public consumption, you can do a count before launching the operation and provide a yes/no option to continue. 1 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.