Skip to content

Commit

Permalink
Fix: Make relative paths for UNC on Windows (#34)
Browse files Browse the repository at this point in the history
* fix already relative paths

* added OSError exception for make relative path

* refactor for loops in one

* fix not statement with filepath.startswith

* refactor list concat with itertools chain

---------

Co-authored-by: kaamaurice <kaalium@gmail.com>
  • Loading branch information
Tilix4 and kaamaurice committed Sep 20, 2023
1 parent c2487c6 commit dfa49bd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions openpype/hosts/blender/utility_scripts/make_paths_relative.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Make all paths relative."""

from pathlib import Path
from itertools import chain
import bpy

from openpype.lib.log import Logger
Expand All @@ -9,6 +11,20 @@
log.debug(
f"Blend file | All paths converted to relative: {bpy.data.filepath}"
)
# Resolve path from source filepath with the relative filepath
for datablock in chain(bpy.data.libraries, bpy.data.images):
try:
if (
datablock
and not datablock.is_library_indirect
and not datablock.filepath.startswith("//")
):
datablock.filepath = bpy.path.relpath(
str(Path(datablock.filepath).resolve()),
start=str(Path(bpy.data.filepath).parent.resolve()),
)
except (RuntimeError, ReferenceError, ValueError, OSError) as e:
log.error(e)

bpy.ops.file.make_paths_relative()
bpy.ops.wm.save_mainfile()

0 comments on commit dfa49bd

Please sign in to comment.