Forum Archive

Action menu entry 'Run selected lines'?

DrNo152

How would one code a script that would work like the menu entry 'Run selected lines' in IEP when called as an action menu entry from the editor? All definitions made in the snippet should be referable in the console afterwards.

omz

That's currently not possible because the console runs in a separate interpreter that isn't accessible from scripts that are run from the editor or action menu. That might change in a future release though.

DrNo152

Thanks for changing this in 1.4. The following simple action does now the trick:

# run selected lines

import editor
import console

text = editor.get_text()
selection = editor.get_line_selection()
selected_text = text[selection[0]:selection[1]]
exec selected_text in globals(), locals()

console.hud_alert('finished','success',0.5)
Gerzer

Thanks, that script will be really useful for me!