Skip to content

Commit

Permalink
add update_script_args
Browse files Browse the repository at this point in the history
similar function as set_named_arg but updates the entire args of the script as opposed to single variable
  • Loading branch information
w-e-w committed Jan 22, 2024
1 parent 118a227 commit f0ef4e8
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions modules/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,29 @@ def set_named_arg(self, all_script_args, script_name, arg_elem_id, value):

assert False, f"arg_elem_id {arg_elem_id} not found in script {script_name}"

def update_script_args(self, all_script_args, script_name, update_args):
"""Update a script's args in script_args
Args:
all_script_args:
script_name:
update_args:
Returns:
Updated script args
"""
script = next((x for x in self.scripts if x.name == script_name), None)
if script is None:
assert False, f"script {script_name} not found"

assert len(update_args) == script.args_to - script.args_from, f"update_args length ({len(update_args)}) doesn't match {script_name} script's args length ({script.args_to - script.args_from})"

if isinstance(all_script_args, list):
all_script_args[script.args_from:script.args_to] = update_args
return all_script_args
else:
return all_script_args[:script.args_from] + tuple(update_args) + all_script_args[script.args_to:]


scripts_txt2img: ScriptRunner = None
scripts_img2img: ScriptRunner = None
Expand Down

0 comments on commit f0ef4e8

Please sign in to comment.