1
$\begingroup$

I'm creating some simple scripts to automatize my workflow. Things like:

import bpy
# import find_and_close_open_edges

def select_by_pattern(name="SovereignMace",part=None,number=None,partsep="_",numsep="."):

    # Sql NVL
    xstr = lambda s: s or "*"

    # name = "Name_<part>[.partnumber]"
    if name is None:
        pattern = ""
    elif part is None:
        pattern = name
    elif number is None:    
        pattern = name + partsep + part
    else:
        pattern = name + partsep + part + numsep + number

    pattern = pattern + "*"

    # pattern = xstr(name) + xstr(partsep) + \
    # xstr(part) + xstr(numsep) + \
    # xstr(number)

    print("Pattern:",pattern)

    # deselect all
    bpy.ops.object.select_all(action='DESELECT')

    # select all objects by pattern
    bpy.ops.object.select_pattern(pattern=pattern)

    return {'FINISHED'}

They grow in number, and they become to be dependent on each other. I use an external editor, so I seldom need to reload one or more script at once and the run them in Blender text editor by ALT-P. Is there a way to reload all scripts used in Blender text editor at once? (Mind I'm not asking how to do F8 reload... that's unrelated) Thank you

$\endgroup$
  • 1
    $\begingroup$ I'd suggest convert all scripts into one addon instead (convert all functions into operators, what is probably needed at some point anyway), then press F8 to reload. Related: blender.stackexchange.com/questions/31126/… BTW: There is no reason to return FINISHED (if it's not an operator), have a look into the templates. $\endgroup$ – brockmann Apr 27 '18 at 10:44
  • $\begingroup$ thanks, it's too early for an addon at present...just looking for a fast tweak... $\endgroup$ – Kabu Apr 27 '18 at 11:20
  • 1
    $\begingroup$ Related $\endgroup$ – batFINGER Apr 27 '18 at 13:23
0
$\begingroup$

Here's a script who does the job:

import bpy

# https://blenderartists.org/forum/showthread.php209369-Synchronizing-text-with-changes-from-outside

def execute():
    """ Check modified external scripts in the scene and update if possible
    """
    ctx = bpy.context.copy()
    #Ensure  context area is not None
    ctx['area'] = ctx['screen'].areas[0]
    for t in bpy.data.texts:
        if t.is_modified and not t.is_in_memory:
            print("  * Warning: Updating external script", t.name)
            # Change current context to contain a TEXT_EDITOR
            oldAreaType = ctx['area'].type
            ctx['area'].type = 'TEXT_EDITOR'
            ctx['edit_text'] = t
            bpy.ops.text.resolve_conflict(ctx, resolution='RELOAD')
            #Restore context
            ctx['area'].type = oldAreaType

execute()

you can run the script in the text editor or console, and it will reload all scripts which are into text editor and have been modified.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.