Looking for a way to run a command after a block is updated

Hello all,

I would like to have Rhino automatically run a command after a block has been edited.
So far my best attempt at achieving this has been with the Alerter command, which I have tried to set up to watch the BlockEdit command, but so far have not been able to get it to actually alert.

Does anyone have an idea on possible ways to achieve this? It seems there may be ways to create a script to constantly watch for block updates, or to have a plugin do something similar. Since I have not been able to find anything related to this topic, Iā€™m hoping someone can point me in the right direction before I get too tangled up in the weeds.

Thanks in advance for any input!

Hi @Samuel_Dwyer,

usually you would add an event watcher which looks if a command has started or ended and write a function which is called before or after that command. This works for many commands, eg. below example prints something after the _Line command completed:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def MyEndCommandEvent(sender, e):
    if e.CommandEnglishName == "Line":
        print "You ended the Line command: ", e.CommandResult

def DoSomething():
    key = "MyEndCommandEvent"
    if scriptcontext.sticky.has_key(key):
        print "Event removed"
        Rhino.Commands.Command.EndCommand -= scriptcontext.sticky[key]
        scriptcontext.sticky.Remove(key)
    else:
        print "Event added"
        scriptcontext.sticky[key] = eval(key)
        Rhino.Commands.Command.EndCommand += eval(key)

if __name__=="__main__":
    DoSomething()

The command _BlockEdit however is a special case where a dialog opens and stays modeless, which means a user can still interact with Rhino. I think, modeless dialogs have no return value so Rhino thinks the command ended right after the dialog is shown.

There is a hidden command however which ends after _BlockEdit ended which you could use instead in the event function:

def MyEndCommandEvent(sender, e):
    if e.CommandEnglishName == "BlockEditApplyInPlaceEditItemChanges":
        print "You ended the BlockEdit command: ", e.CommandResult

Here is more information about the same problem.

@dale, i think this is a bug or at least a limitation, if you eg. try to wait for the completion of the BlockEdit command using a macro like this:

! _-BlockEdit _MultiPause _SelBlockInstance

it should select the edited block after the command has completed, however, the command is not paused. It immediately prints this to the command line:

Command: _SelBlockInstance
No objects added to selection.

Is there some room for improvement ?

_
c.

1 Like

@Samuel_Dwyer, small addendum, in case of nested blocks, also note this limitation.

1 Like

@clement This worked perfectly! Thank you for your reply and in-depth explanation, especially on the intricacies of BlockEdit.