0

The follwowing is a code written in blender python

import bpy
import os
import subprocess
import time
bpy.data.materials["Material"].use_face_texture = True
customer_id = "john33"
image1 = "orangeskin.jpg" # define image 1 from folder
imagepath1 = "C:\\Users\\mrryan\\Desktop\\models\\materialsjpeg\\" 
image2 = "elec.jpg"
imagepath2 = "C:\\Users\\mrryan\\Desktop\\models\\materialsjpeg\\" 

#Step 1 go to Edit Mode
bpy.ops.object.editmode_toggle()

#step 2 insert image in the Image Editor
bpy.context.area.type = 'IMAGE_EDITOR'
bpy.ops.uv.smart_project()
bpy.ops.image.open(filepath = image1, directory= imagepath1 , 
files=[{"name":image1, "name":image1}])

#Step 3 back to Object Mode TRY AND CHANGE TITLE TO `CUSTOMER_ID AND FILE`
bpy.ops.object.editmode_toggle()
bpy.data.window_managers["WinMan"].sketchfab.title = "orangetube"



#Step 4 save new.blend   
filepath = os.path.join(r"C:\Users\mrryan\Desktop", customer_id + "orangytube.blend")
bpy.ops.wm.save_as_mainfile(filepath = filepath)
toggleedit = bpy.ops.object.editmode_toggle()
#here is the problem!!!!
subprocess.call(["bpy.ops.export.sketchfab()"], shell = True)



#new texture
#Step 1 go to Edit Mode


#step 2 insert image in the Image Editor
bpy.context.area.type = 'IMAGE_EDITOR'

bpy.ops.image.open(filepath= image2, directory= imagepath2, 
files= [{"name":image2,"name":image2}])    
bpy.ops.uv.smart_project()

#Step 3 back to Object Mode
bpy.ops.object.editmode_toggle()
bpy.data.window_managers["WinMan"].sketchfab.title = "elec-tube"
#Step 4 save new.blend
filepath = os.path.join(r"C:\Users\mrryan\Desktop", customer_id + "elec-tube.blend")
bpy.ops.wm.save_as_mainfile(filepath = filepath)
bpy.ops.export.sketchfab()

The idea is, eventually to programmatically change the active object( which is combined but not joined with another object) to have different materials and change the shape, etc. Each individual model combination would be uploaded to sketchfab separately and saved as a blender file.

At this stage my problem is that, while uploading, the script does not wait until the first upload is finished.This generates an error that says to please wait for the current upload to finish. and as a result only one model is uploaded. subprocess.Popen has been tried but i could not get it to work. Perhaps the return values were wrong? How can you get the script to upload the first model, wait until finished, then continue to make the adjustments and upload the second?

1 Answers1

0

(I work at Sketchfab, but I don't have much experience in Blender scripting).

The issue is that the Sketchfab Blender Exporter uses a thread for the upload, meaning the subprocess will return, with a thread still running in the background.

I would experiment in launching bpy.ops.export.sketchfab() using a new Thread and join(), instead of just subprocess.

The following resources might help:

Let us know how it goes!

Community
  • 1
  • 1