From: Janos Kutscherauer on
Hi,

i am trying to facilitate a mechanism to lock blocks in Simulink, so that users cannot move or resize them. My approach is to catch the "MoveFcn" callback (which is triggered when a block was moved or resized), and set the blocks position to the previously stored value.

Simulink recognizes, that setting the 'Position' parameter within the 'MoveFcn' callback handler might cause a recursion, and although it actually executes my code, it throws the warning:

Warning: Error evaluating 'MoveFcn' callback of Scope block 'simpleModel/Scope'. Error using ==> set_param Recursion detected in the MoveFcn of 'simpleModel/Scope'.

I thought i could workaround it by first unsetting the 'MoveFcn' callback function, then resetting the position value, and finally setting the callback function again. But still Simulink recognized recursion.

This is the code, which even checks if the new value is different to the stored value.

> %checkLock.m
> set_param(gcb, 'MoveFcn', '');
> storedPos = [470 64 500 96];
> currentPos = get_param(gcb, 'Position');
> if ~isequal(storedPos, currentPos)
> set_param(gcb, 'Position', storedPos);
> end
> set_param(gcb, 'MoveFcn', checkLock);

This produces the warning mentioned above. I think the code takes care of recursions pretty well (not sure about the timing, when i unregister and re-register the callback function, but the condition does prevent recursive calls!).

Is there any workaround specifically for preventing resizing/movement of blocks, or more generally for handling this kind of recursion warnings?

Thanks for your comments!
Cheers
Janos