Skip to main content
sonson_twit
Participating Frequently
February 7, 2024
Question

How can I control Substance 3D plugin for Blender via Blender Python API?

  • February 7, 2024
  • 1 reply
  • 387 views

I want to load a sbsar file and attach the material to any objects using Python API.

 

Like following pseudo codes,

 

import bpy
import substance3d

path = '<path/to/sbsar_file>'
substance3d.obj.load(path)
material = bpy.context.materials['name_of_sbsar']
object = bpy.context.selected_objects[0]
object.data.materials.append(material)

 

I have used Blender 4.0 and new Substance 3D Plugin for Blender.

 

Does anyone have any good advices?

This topic has been closed for replies.

1 reply

sonson_twit
Participating Frequently
February 7, 2024

Sorry, that wasn't hard.

 

import bpy
bpy.ops.substance.load_sbsar(filepath="<path>/hoge.sbsar", files=[{"name":"hoge.sbsar"}], directory="<path>")
Community Manager
February 7, 2024

Thanks for sharing this! We'll capture it in our documentation 

sonson_twit
Participating Frequently
February 8, 2024

But.... It wasn't that easy, again.

 

Addon initializer and SBSAR loading function are executed on another thread.

I want to attach the material which is created from sbsar file to any objects, but materials are still empy after loading a SBSAR file.

I do not know how to wait these threads....