Open willDTF opened 3 years ago
We are also experiencing this issue. The problem is specific to anywhere in any of the paths that have any \n
for example: C:\programs\Nuke\.....
would result in a broken path containing a newline. Since Nuke expects /
as separator no matter the parent OS the os.path.join
calls could be replaced with "/".join([...])
?
replace all instances of
.nk")
with
.nk").replace("\\","/")
and all .nk tools work again. It's not the sexiest solution but it works.
Instead of doing .nk").replace("\\","/")
another fix is to use os.path.normpath
. It gets you the same result and will work if you/ your company works on either Windows, Mac, or Linux.
ex: NST_FolderPath = os.path.normpath(os.path.dirname(__file__))
Because so many of the path stubs are hard-coded in for anything that pastes in a .nk file (similar to using a ToolSet), adding in os.path.normpath
doesn't fully fix the issue on windows.
No fix:
nuke.nodePaste("C:/Users/jointadmin/.nuke\nukeTools\NukeSurvivalToolkit/nk_files/Noise.nk")
os.path.normpath
patch:
nuke.nodePaste("C:\Users\jointadmin\.nuke\nukeTools\NukeSurvivalToolkit/nk_files/Noise.nk")
So that fixes the backslashes in the middle for Windows, but doesn't fix the hardcoded path at the end. Suppose I'll have to hand code all those replacement backslash escape fixes.
Hello @powerllama,
I have something that maybe could help to fix this issue. I make an example with pathlib, it fix the backslash but do a weird thing with the root :
import pathlib
script_path = r"C:/Users/jointadmin/.nuke\nukeTools\NukeSurvivalToolkit/nk_files/Noise.nk"
purepath = pathlib.PurePath(script_path)
wind_path = pathlib.PureWindowsPath(purepath)
posix_path = pathlib.PurePosixPath(purepath)
print(purepath)
# C:/Users/jointadmin/.nuke\nukeTools\NukeSurvivalToolkit/nk_files/Noise.nk
print(wind_path)
# C:Users\jointadmin\.nuke\nukeTools\NukeSurvivalToolkit\nk_files\Noise.nk
print(posix_path)
# C:/Users/jointadmin/.nuke\nukeTools\NukeSurvivalToolkit/nk_files/Noise.nk
I don't have time now to dig more but hope it'll help!
The issue is having to go through and replace all of those hard coded paths. I just made a vim macro and added the replace function to all of the strings I needed to 😂
thank you vim
Created a pull request replacing all of the os.join stuff with Path objects, maybe Tony will like it enough to merge it into main.
Because so many of the path stubs are hard-coded in for anything that pastes in a .nk file (similar to using a ToolSet), adding in
os.path.normpath
doesn't fully fix the issue on windows.No fix:
nuke.nodePaste("C:/Users/jointadmin/.nuke\nukeTools\NukeSurvivalToolkit/nk_files/Noise.nk")
os.path.normpath
patch:nuke.nodePaste("C:\Users\jointadmin\.nuke\nukeTools\NukeSurvivalToolkit/nk_files/Noise.nk")
So that fixes the backslashes in the middle for Windows, but doesn't fix the hardcoded path at the end. Suppose I'll have to hand code all those replacement backslash escape fixes.
Ah I didn't realize that was hard coded. Another alternative is to check what OS is being used and replace the all hardcoded file paths with the right slash directions.
Ideally all hardcoded paths can be on in a constants.py
file and are then imported from there. This way any string manipulation that needs to happen can all happen in the constants.py
file instead of throughout the code base.
I believe that would solve the problem entirely.
Because so many of the path stubs are hard-coded in for anything that pastes in a .nk file (similar to using a ToolSet), adding in
os.path.normpath
doesn't fully fix the issue on windows. No fix:nuke.nodePaste("C:/Users/jointadmin/.nuke\nukeTools\NukeSurvivalToolkit/nk_files/Noise.nk")
os.path.normpath
patch:nuke.nodePaste("C:\Users\jointadmin\.nuke\nukeTools\NukeSurvivalToolkit/nk_files/Noise.nk")
So that fixes the backslashes in the middle for Windows, but doesn't fix the hardcoded path at the end. Suppose I'll have to hand code all those replacement backslash escape fixes.Ah I didn't realize that was hard coded. Another alternative is to check what OS is being used and replace the all hardcoded file paths with the right slash directions.
Ideally all hardcoded paths can be on in a
constants.py
file and are then imported from there. This way any string manipulation that needs to happen can all happen in theconstants.py
file instead of throughout the code base.I believe that would solve the problem entirely.
if you look at this pull request, i solved it using the pathlib module which handles paths between operating systems in a much more graceful way https://github.com/CreativeLyons/NukeSurvivalToolkit_publicRelease/pull/37
Using Windows 10, NST_FolderPath = os.path.dirname(file) return backslashes indeed of slashes / so nuke won't open the .nk file selected I fixed it with the replace function