How to abort a script?

Hi all,

I have done a script which can automatically find blocks to explode and group it.
But in some case there are too many blocks and it takes too long.
I try to hit ‘Esc’ but it doesn’t abort the script ( I remember in rhinoscript you can always hit ‘Esc’ to abort )
Just wondering is there anyway I can abort a script when it runs too long?
Should I add some lines like ’ if (I hit Esc ) : abort '.

Below is my script:

import rhinoscriptsyntax as rs

rs.Command("_SelBlockInstance")
Blocks = rs.GetObjects(“Pick Blocks”,4096,False,True)
for b in Blocks:
rs.SelectObject(b)
rs.Command("_ExplodeBlock")
rs.Command("_SelLast")
rs.Command("_Group")

rs.Command("_SelNone")

Many Thanks,

Jack

Escape only works between operations. I think you have all blocks selected after _SelBlockInstance. Perhaps put a Rhino.UnselectAllObjects before your loop?

Hi David,

Thanks for your prompt reply.
But I think the '_SelNone doesn’t help much…
Because it only pick 1 block to explode in each loop.
The problem is when I found there are too many blocks and it needs to loop too many times I cannot abort…
So you mean, when we are in a loop, there is no way to abort the script? If we hit “Esc” it only escape the operations in this loop but cannot stop the entire loop?

So there is no manual way to abort a script.
We can only put some lines in the loop when it meet some condition then let it return?

You might want to check out this thread… --Mitch

rs.Command("_SelBlockInstance")
(at this point all blocks are selected, plus whatever other objects were selected already)

Blocks = rs.GetObjects(“Pick Blocks”,4096,False,True)
(at this point all blocks are still selected, but nothing else should be)

for b in Blocks:
rs.SelectObject(b)
(You’re selecting an object which is already selected)

rs.Command("_ExplodeBlock")
(You run a command which takes the entire selection into account, which is all blocks)

rs.Command("_SelNone")
(After you’re done you deselect everything.)


I haven’t run your code, but that is what I thought might be going on. You do not deselect all your blocks before you run the ExplodeBlock command, thus your script is not cancellable because it’s a single instruction which takes all the time.

Ah…I see, I understand now, my bad…
Thanks David!!

Jack

Thank you Helvetosaur!