1
$\begingroup$

I am using Blender 2.93.4 on MacOS 10.15 and followed the build instructions for the Sketchup Importer on Arindam Mondal's version 0.23.

Because the Cycles renderer is not available on my graphics card, I was getting errors when the addon attempted to load geometries and materials, so I manually edited /sketchup_importer/__init__.py to change all references from "CYCLES" to "BLENDER_EEVEE".

Now, when running the importer on a path that has spaces or dashes, I get the following error on any file I try to load:

Python: Traceback (most recent call last):
  File "/Users/palazzo/Library/Application Support/Blender/2.93/scripts/addons/sketchup_importer/__init__.py", line 982, in execute
    return SceneImporter().set_filename(keywords['filepath']).load(
  File "/Users/palazzo/Library/Application Support/Blender/2.93/scripts/addons/sketchup_importer/__init__.py", line 236, in load
    self.write_materials(self.skp_model.materials)
  File "/Users/palazzo/Library/Application Support/Blender/2.93/scripts/addons/sketchup_importer/__init__.py", line 433, in write_materials
    os.mkdir(temp_dir)
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/nr/50wh3xf90rb5lqnrf0vpwtz00000gn/T\\/path/to/my/sketchup-file'

location: <unknown location>:-1

The larger context of the offending code (__init__.py around line 433) is this:

if tex:
    tex_name = tex.name.split("\\")[-1]
    temp_dir = tempfile.gettempdir()
    skp_fname = self.filepath.split("\\")[-1].split(".")[0]
    temp_dir += '\\' + skp_fname
    if not os.path.isdir(temp_dir):
        os.mkdir(temp_dir)
    temp_file_path = os.path.join(temp_dir, tex_name)
    tex.write(temp_file_path)
    img = bpy.data.images.load(temp_file_path)
    img.pack()

I am sure there must be a straightforward way of solving this in the code, but I only have the most basic idea of how Python works, so I would appreciate a hint. It’s not a deal-breaker given that it can be worked around without changing the code, but it would be nice to have it robustly solved.

$\endgroup$
10
  • $\begingroup$ Add-ons are (usually) not exclusive to any OS. If the add-on works on Windows or Linux, there is no reason why it shouldn't work on OSX. -> How to download and install an add-on hosted on github properly? $\endgroup$
    – brockmann
    Commented Sep 6, 2021 at 12:46
  • $\begingroup$ Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. $\endgroup$
    – Community Bot
    Commented Sep 6, 2021 at 13:49
  • $\begingroup$ When you say they refuse to activate, what errors are you seeing when you try to activate them? @brockmann is correct, it is rare for an add-on to work on one OS but not another because they are mostly written in a portable form of Python, so I'm surprised they won't work for you. Both of those add-ons require that you also install the sketchup API. arindam-m has instructions for doing that. $\endgroup$ Commented Sep 6, 2021 at 14:00
  • $\begingroup$ @brockmann in theory this should be the case. However, the arindam-m repo specifically states the plugin is intended for Windows-x64 systems, for example. $\endgroup$ Commented Sep 9, 2021 at 14:32
  • $\begingroup$ First headline of arindam-m repo is "OSX Build info": github.com/arindam-m/pyslapi#osx-build-info, not sure what do you mean...? $\endgroup$
    – brockmann
    Commented Sep 9, 2021 at 14:39

1 Answer 1

2
$\begingroup$

Converting the snippet using pathlib.

Feel this is bordering on off-topic, in lieu of a further long comment will add a fix to code snippet in question to convert to pathlib , always happy to spruik for pathlib.

The code snippet shown appears to be written exclusively for MS Windows OS which uses backslashes as path separator.

Please check out the following medium links, especially the first as it goes a long way to explaining the issue & the process to fix

Python 3 Quick Tip: The easy way to deal with file paths on Windows, Mac and Linux

Pathlib Is Wonderful!

Five Most Useful Pathlib Operations

import bpy
from pathlib import Path

# used here only to emulate tex and self
from types import SimpleNamespace

tex = SimpleNamespace(
     name="/usr/batfinger/Desktop/batman.png",
     write=print
    )

self = SimpleNamespace(
    filepath="/some/path/to/sketchupfile.skp"
    )

# convert to pathlib

if tex:
    #tex_name = tex.name.split("\\")[-1]
    tex_name = Path(tex.name).name
    #temp_dir = tempfile.gettempdir()
    #skp_fname = self.filepath.split("\\")[-1].split(".")[0]
    skp_fname = Path(self.filepath).stem
    
    #temp_dir += '\\' + skp_fname
    temp_dir = Path(bpy.app.tempdir) / skp_fname
    #if not os.path.isdir(temp_dir):
    #    os.mkdir(temp_dir)
    if not temp_dir.exists():
        temp_dir.mkdir()
        
    #temp_file_path = os.path.join(temp_dir, tex_name)
    temp_file_path = temp_dir / tex_name
    #tex.write(temp_file_path)
    tex.write(str(temp_file_path)) # convert path to string
    '''
    # I assume that tex.write saves the image to the temp path
    # Which can then be loaded into
    img = bpy.data.images.load(str(temp_file_path))
    # and packed
    img.pack()
    '''

Test output from "tex.write" print

/tmp/blender_Zflkkv/sketchupfile/batman.png

which is image with same name as tex in blender file temp folder within a folder named after sketchup file stem (the name without the extension) sketchupfile

Not using the addon or sketchup to check, but if tex.name is the filepath to an image, can't see why not to simply load in img = bpy.data.images.load(tex.name) and then pack the file.

$\endgroup$
2
  • $\begingroup$ Batman.png was used, immediately upvoted. $\endgroup$
    – brockmann
    Commented Sep 11, 2021 at 11:48
  • $\begingroup$ Thanks. I will have to investigate a chain of other errors this triggers, but it looks like the best starting point. $\endgroup$ Commented Sep 12, 2021 at 19:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .