Remap: Refactor scripts #177
@ -77,26 +77,15 @@ def get_josn_file_dir() -> str:
|
||||
return Path(json_dir).joinpath("dir_map.json").__str__()
|
||||
|
||||
|
||||
def save_bbatch_script():
|
||||
def get_bbatch_command():
|
||||
directory = get_current_dir()
|
||||
source_file = directory.joinpath('remap_blender_paths.py')
|
||||
variables = get_variables()
|
||||
new_file_dir = directory.joinpath('dist')
|
||||
|
||||
with open(source_file, 'r', encoding='utf-8') as source_file:
|
||||
data = source_file.readlines()
|
||||
for line in data:
|
||||
if line.startswith('json_file_path ='):
|
||||
data[data.index(line)] = f'json_file_path = "{variables[JSON_FILE_KEY]}"'
|
||||
mapped_dir_name = Path(variables[CRAWL_DIR_KEY]).name
|
||||
new_file = new_file_dir.joinpath(f'remap_blender_paths_for_{mapped_dir_name}.py')
|
||||
|
||||
with open(new_file, 'w', encoding='utf-8') as source_file:
|
||||
source_file.writelines(data)
|
||||
print(f"bbatch script has been saved to {new_file.__str__()}")
|
||||
print("This is your bbatch command")
|
||||
print(
|
||||
f'python -m bbatch {variables[CRAWL_DIR_KEY]} --script {new_file.absolute().__str__()} --nosave --recursive'
|
||||
"To update your .blend file references open the bbatch directory and run the following command"
|
||||
)
|
||||
print(
|
||||
f'python -m bbatch {variables[CRAWL_DIR_KEY]} --nosave --recursive --script {source_file} --args {variables[JSON_FILE_KEY]}'
|
||||
)
|
||||
|
||||
|
||||
@ -178,7 +167,7 @@ def main():
|
||||
variables[CRAWL_DIR_KEY], variables[JSON_FILE_KEY]
|
||||
)
|
||||
print('Map update is complete')
|
||||
save_bbatch_script()
|
||||
get_bbatch_command()
|
||||
elif answer_lw == "no" or answer_lw == 'n':
|
||||
remove_variable_file()
|
||||
main()
|
||||
|
@ -1,4 +1,4 @@
|
||||
import argparse
|
||||
import sys
|
||||
import bpy
|
||||
from pathlib import Path
|
||||
import json
|
||||
@ -9,14 +9,6 @@ from typing import List
|
||||
|
||||
file_updated = False
|
||||
|
||||
# Command line arguments.
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"path",
|
||||
help="Path to JSON file containing map",
|
||||
type=str,
|
||||
)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def override_save_version():
|
||||
@ -170,9 +162,11 @@ def update_libs(file_map_dict: dict) -> None:
|
||||
def remap_all_blender_paths():
|
||||
"""Remap all references to files from blender via dictionary"""
|
||||
start = time.time()
|
||||
import sys
|
||||
|
||||
args = parser.parse_args()
|
||||
json_file_path = args.path
|
||||
argv = sys.argv
|
||||
argv = argv[argv.index("--") + 1 :]
|
||||
json_file_path = argv[0]
|
||||
|
||||
file_map_json = Path(json_file_path)
|
||||
file_map_data = open(file_map_json)
|
||||
|
Loading…
Reference in New Issue
Block a user