1

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.

  • 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? – brockmann Sep 06 '21 at 12:46
  • 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. – Community Sep 06 '21 at 13:49
  • 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. – Marty Fouts Sep 06 '21 at 14:00
  • @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. – Pedro Palazzo Sep 09 '21 at 14:32
  • First headline of arindam-m repo is "OSX Build info": https://github.com/arindam-m/pyslapi#osx-build-info, not sure what do you mean...? – brockmann Sep 09 '21 at 14:39
  • Thank you for the heads up, @MartyFouts. I just bypassed Arindam Mondal's fork after seeing it was labeled for Windows and did not pay attention to the fact his README provided instructions for installing on Mac. I was able to install and activate the plugin (but not do any successful import), and will edit my question accordingly. – Pedro Palazzo Sep 09 '21 at 15:14
  • And thank you @brockmann as well. I can’t believe I overlooked the README. – Pedro Palazzo Sep 09 '21 at 15:37
  • The code snippet shown appears to be specifically for windows OS, which uses backslash file separator. Would look into using pathlib eg skpfname = pathlib.Path(self.filename).stem – batFINGER Sep 09 '21 at 15:59
  • Thank you @batFINGER. This change does not seem very straightforward; after importing pathlib and replacing the offending line with your suggestion, the addon complains there is no such property as filename. Using filepath does not work either. – Pedro Palazzo Sep 09 '21 at 17:52
  • Yes did mean self.filepath Just about every line needs replacing, first one tex_name = Path(tex.name).name instead of last item aft splitting it by the windows file path separator. (backslash) ... could convert the whole snippet, but would it answer question or only lead to next issue?. – batFINGER Sep 09 '21 at 18:10

1 Answers1

2

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.

batFINGER
  • 84,216
  • 10
  • 108
  • 233