Skip to content

Commit 4928123

Browse files
committed
ensure blend path is relative to zipfile in json
1 parent 93887e8 commit 4928123

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

stand_alone_scripts/export_helper.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,7 @@ def make_rel(path: Path) -> Path:
247247
for world in bpy.data.worlds:
248248
save_out_preview(world, d)
249249

250-
bpy.ops.wm.save_mainfile(filepath=str(d / blend_path.name), compress=True)
250+
# Save the blend file
251+
out_path = d / blend_path.name
252+
bpy.ops.wm.save_mainfile(filepath=str(out_path), compress=True)
253+
print(f"=out_path={out_path}")

utils.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ def id_to_asset_id_type(id: ID) -> str:
10621062

10631063

10641064
@contextmanager
1065-
def display_all_assets_in_library(context: Context) -> None:
1065+
def display_all_assets_in_library(context: Context) -> Generator[None, None, None]:
10661066
"""Makes all possible assets visible in the UI for the duration of the context manager. Assets are all selected so running `context.selected_assets` will return all assets."""
10671067
# Gather Current State ##
10681068
# Params
@@ -1563,6 +1563,18 @@ def handle_preview_path(v: str):
15631563
else:
15641564
print(f"Could not find asset: '{item_name}' of type '{item_type}' in blend file: {blend_file}")
15651565

1566+
def handle_out_path(v: str) -> None:
1567+
for asset_dict in json_dict["assets"]:
1568+
if Path(asset_dict["blend_path"]) == blend_file:
1569+
path = Path(v)
1570+
if path.is_relative_to(destination_dir):
1571+
path = path.relative_to(destination_dir)
1572+
asset_dict["blend_path"] = str(path)
1573+
else:
1574+
print(
1575+
f"Out path is not relative to destination directory. Probably saved in wrong place!\n\t{path}"
1576+
)
1577+
15661578
if op:
15671579
while True:
15681580
line = proc.stdout.readline()
@@ -1582,6 +1594,8 @@ def handle_preview_path(v: str):
15821594
op.movingfiles_sub_prog = float(value)
15831595
case "preview_path":
15841596
handle_preview_path(value)
1597+
case "out_path":
1598+
handle_out_path(value)
15851599
case _:
15861600
print("Unhandled Property:", prop, ", value:", value)
15871601
op.updated = True
@@ -1608,8 +1622,11 @@ def handle_preview_path(v: str):
16081622
elif line.startswith("="):
16091623
prop, value = line[1:].split("=")
16101624
value = value.replace("\n", "")
1611-
if prop == "preview_path":
1612-
handle_preview_path(value)
1625+
match prop:
1626+
case "preview_path":
1627+
handle_preview_path(value)
1628+
case "out_path":
1629+
handle_out_path(value)
16131630

16141631
if proc.returncode > 1:
16151632
print()

0 commit comments

Comments
 (0)