bpy.ops.wm.save_as_mainfile does not work as expected on MacOS when run from script #67118

Closed
opened 2019-07-17 13:11:28 +02:00 by Oliver Dawes · 17 comments

System Information
Operating system: MacOS

Blender Version
Blender 2.8 Candidate Release (didn't try 2.79 but I suspect the same problem)

Short description of error
On MacOS the operator bpy.ops.wm.save_as_mainfile(copy=True, filepath=path, relative_remap=True, compress=True) saves the current blend scene as a copy but does find external assets when run from a script however saving through the interface using "File > Save Copy... > " does work as intended (I was under the impression that the interface is just running this operator under the hood which is why I am surprised to see different results)

Exact steps for others to reproduce the error

  • open a new unsaved blender file
  • add a texture to the default cube to act as an external asset
  • run the following script from blenders text editor
import bpy

# feel free to change path (I am saving to a temporary directory)
path='/var/folders/94/tdrqyvln2_bfkdxctp3ktdr40000gn/T/gm-temp-dir-6fzcf_08/file_saved_through_script.blend'

bpy.ops.wm.save_as_mainfile(copy=True, filepath=path, relative_remap=True, compress=True)

You should see a similar messages in the system console:

Info: Total files 1 | Changed 1 | Failed 0`
Path /private/Users/<user name>/Pictures/test_texture.jpg does not exist for <BlockUsage name=b'IMartsoc5.jpg' type='Image' field='name[1024]' asset=BlendPath(b'//../../../../../../Users/<user name>/Pictures/test_texture.jpg')>```

However if you save a copy through the interface you just get:

Info: Total files 1 | Changed 1 | Failed 0

(no weird does not exist error)

Note - I have tested on Windows and Linux and it works as expected in both these environments. I encountered this issue as I am trying to write a blender add-on that requires packing the current blender scene before upload. I am using Blender Asset Tracer (BAT) to do this and it works well. I save a copy of the current scene to a temporary blend file and pack that file, however on MacOS this packed file never contains external assets and it appears to be because `bpy.ops.wm.save_as_mainfile` is not working correctly.
**System Information** Operating system: MacOS **Blender Version** Blender 2.8 Candidate Release (didn't try 2.79 but I suspect the same problem) **Short description of error** On MacOS the operator `bpy.ops.wm.save_as_mainfile(copy=True, filepath=path, relative_remap=True, compress=True)` saves the current blend scene as a copy but does find external assets when run from a script however saving through the interface using "File > Save Copy... > <same output location as script>" does work as intended (I was under the impression that the interface is just running this operator under the hood which is why I am surprised to see different results) **Exact steps for others to reproduce the error** - open a new unsaved blender file - add a texture to the default cube to act as an external asset - run the following script from blenders text editor ``` import bpy # feel free to change path (I am saving to a temporary directory) path='/var/folders/94/tdrqyvln2_bfkdxctp3ktdr40000gn/T/gm-temp-dir-6fzcf_08/file_saved_through_script.blend' bpy.ops.wm.save_as_mainfile(copy=True, filepath=path, relative_remap=True, compress=True) ``` You should see a similar messages in the system console: ``` Info: Total files 1 | Changed 1 | Failed 0` Path /private/Users/<user name>/Pictures/test_texture.jpg does not exist for <BlockUsage name=b'IMartsoc5.jpg' type='Image' field='name[1024]' asset=BlendPath(b'//../../../../../../Users/<user name>/Pictures/test_texture.jpg')>``` However if you save a copy through the interface you just get: ``` Info: Total files 1 | Changed 1 | Failed 0 ``` (no weird does not exist error) Note - I have tested on Windows and Linux and it works as expected in both these environments. I encountered this issue as I am trying to write a blender add-on that requires packing the current blender scene before upload. I am using Blender Asset Tracer (BAT) to do this and it works well. I save a copy of the current scene to a temporary blend file and pack that file, however on MacOS this packed file never contains external assets and it appears to be because `bpy.ops.wm.save_as_mainfile` is not working correctly.
Author

Added subscriber: @haiku

Added subscriber: @haiku
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Still unsure if this is related to BAT or plain blender?

That message you see is from BAT...

If you dont use BAT but just run the script you posted, if you then open the file just saved through the script, are the images showing up? (so the paths are still correct?)
If this is the case, then we might have to dig in BAT instead, no?

Still unsure if this is related to `BAT` or plain blender? That message you see is from `BAT`... If you dont use BAT but just run the script you posted, if you then open the file just saved through the script, are the images showing up? (so the paths are still correct?) If this is the case, then we might have to dig in BAT instead, no?
Member

btw., #62612 might be related... (still not sure though why these would actually report as "not existing"...)

btw., #62612 might be related... (still not sure though why these would actually report as "not existing"...)
Author

In #67118#725115, @lichtwerk wrote:
Still unsure if this is related to BAT or plain blender?

That message you see is from BAT...

If you dont use BAT but just run the script you posted, if you then open the file just saved through the script, are the images showing up? (so the paths are still correct?)
If this is the case, then we might have to dig in BAT instead, no?

Sorry I must have been running BAT trace after saving, however I still believe the issue is plain blender.

I just tried running the script with a variety of save locations (No BAT) and here's the result:

  • Saved to /var/folders/94/tdrqyvln2_bfkdxctp3ktdr40000gn/T/file_saved_through_script.blend and when opened in blender the cube was missing it's texture (showed as pink)
  • Saved to /var/folders/94/tdrqyvln2_bfkdxctp3ktdr40000gn/T/gm-temp-dir-6fzcf_08/file_saved_through_script.blend (pink cube again)
  • Saved to /tmp/file_saved_through_script.blend (pink cube again)
  • Saved to /Applications/file_saved_through_script.blend This time the cube had it's texture
  • Saved to /Users/<user name>/file_saved_through_script.blend cube had it's texture
  • Saved to /Users/<user name>/Desktop/file_saved_through_script.blend cube had it's texture

The cube texture was located on the desktop so it looks to me like the paths are correctly re-mapped so long as your saving the file to a location with the same root as the texture. I'm guessing the /Applications folder maps to the /Users/<user name>/Applications folder? I'm not used to MacOS so I may be wrong on that.

I need to be able to save the current blender scene (that may contain relative and absolute paths) as a copy to to some arbitary location in a way that BAT will then be able to pack that copy for distribution.

> In #67118#725115, @lichtwerk wrote: > Still unsure if this is related to `BAT` or plain blender? > > That message you see is from `BAT`... > > If you dont use BAT but just run the script you posted, if you then open the file just saved through the script, are the images showing up? (so the paths are still correct?) > If this is the case, then we might have to dig in BAT instead, no? Sorry I must have been running BAT trace after saving, however I still believe the issue is plain blender. I just tried running the script with a variety of save locations (No BAT) and here's the result: - Saved to `/var/folders/94/tdrqyvln2_bfkdxctp3ktdr40000gn/T/file_saved_through_script.blend` and when opened in blender the cube was missing it's texture (showed as pink) - Saved to `/var/folders/94/tdrqyvln2_bfkdxctp3ktdr40000gn/T/gm-temp-dir-6fzcf_08/file_saved_through_script.blend` (pink cube again) - Saved to `/tmp/file_saved_through_script.blend` (pink cube again) - Saved to `/Applications/file_saved_through_script.blend` This time the cube had it's texture - Saved to `/Users/<user name>/file_saved_through_script.blend` cube had it's texture - Saved to `/Users/<user name>/Desktop/file_saved_through_script.blend` cube had it's texture The cube texture was located on the desktop so it looks to me like the paths are correctly re-mapped so long as your saving the file to a location with the same root as the texture. I'm guessing the `/Applications` folder maps to the `/Users/<user name>/Applications` folder? I'm not used to MacOS so I may be wrong on that. I need to be able to save the current blender scene (that may contain relative and absolute paths) as a copy to to some arbitary location in a way that BAT will then be able to pack that copy for distribution.
Member

Added subscriber: @Mets

Added subscriber: @Mets
Member

Looks like this no longer needs information.

I tested it but... Blender actually just closed for me when running the script, with no message in the console. Is that... what's supposed to happen? It also does not save a file in the path I specified.

Win10 v1607, GTX 1070, 79ce2054d4

Looks like this no longer needs information. I tested it but... Blender actually just closed for me when running the script, with no message in the console. Is that... what's supposed to happen? It also does not save a file in the path I specified. Win10 v1607, GTX 1070, 79ce2054d4
Author

@Mets - Blender shouldn't close, how are you running the script and which line of the script is causing blender to close for you? I was just using blender's internal text editor to run it btw, I didn't try running the script as a command line argument or anything.

@Mets - Blender shouldn't close, how are you running the script and which line of the script is causing blender to close for you? I was just using blender's internal text editor to run it btw, I didn't try running the script as a command line argument or anything.
Member

Welp, today it works fine... Same build, same file, same path. I don't know why it was doing that yesterday... Oh well, I guess what matters is I can't reproduce.

Welp, today it works fine... Same build, same file, same path. I don't know why it was doing that yesterday... Oh well, I guess what matters is I can't reproduce.
Author

@Mets What OS were you using?

@Mets What OS were you using?
Member

Windoze, mentioned in my first comment.

Windoze, mentioned in my first comment.
Author

@Mets Ah I see, I only get the bug on Mac so that makes sense.

@Mets Ah I see, I only get the bug on Mac so that makes sense.

Added subscriber: @robbott

Added subscriber: @robbott

I cannot reproduce this on OSX 10.14.6 . Are you still able to reproduce this on the latest version ?

Operating system: Darwin-18.7.0-x86_64-i386-64bit 64 Bits
Graphics card: AMD Radeon Pro 560X OpenGL Engine ATI Technologies Inc. 4.1 ATI-2.11.20
2.90 (sub 0), branch: master, commit date: 2020-05-09 15:17, hash: 633fee72d5

I cannot reproduce this on OSX 10.14.6 . Are you still able to reproduce this on the latest version ? Operating system: Darwin-18.7.0-x86_64-i386-64bit 64 Bits Graphics card: AMD Radeon Pro 560X OpenGL Engine ATI Technologies Inc. 4.1 ATI-2.11.20 2.90 (sub 0), branch: master, commit date: 2020-05-09 15:17, hash: `633fee72d5`

Added subscriber: @mont29

Added subscriber: @mont29

Changed status from 'Needs Developer To Reproduce' to: 'Resolved'

Changed status from 'Needs Developer To Reproduce' to: 'Resolved'
Bastien Montagne self-assigned this 2020-05-27 15:51:47 +02:00

Cannot reproduce that with current blender either (on linux), so for now will consider it fixed, feel free to reopen if you can still reproduce.

Cannot reproduce that with current blender either (on linux), so for now will consider it fixed, feel free to reopen if you can still reproduce.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#67118
No description provided.