Page 1 of 1

Changing material of the object via blendluxcore python script

Posted: Fri Jan 11, 2019 9:14 am
by pro
Hi,
I want to change the material of an object (for example of a Cube/Plane) in Blender using Blendluxcore, and I want to be able to assign the material via python script.
I found the available materials in blender, I select an object -> Material -> Node Tree Presets -> Matte, Glossy etc.
I also found preset function:

bpy.ops.luxcore.preset_material(preset='Matte')

But when typing it in console it returns:

Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
File "C:\Program Files\Blender Foundation\Blender\2.79\scripts\modules\bpy\ops.py", line 189, in __call__
ret = op_call(self.idname_py(), None, kw)
RuntimeError: Error: Traceback (most recent call last):
File "C:\Users\pro\AppData\Roaming\Blender Foundation\Blender\2.79\scripts\addons\BlendLuxCore\operators\node_tree_presets.py", line 53, in execute
mat = context.material
AttributeError: 'Context' object has no attribute 'material'
location: C:\Program Files\Blender Foundation\Blender\2.79\scripts\modules\bpy\ops.py:189

So my question is simple - how can I achieve to select material for a selected object via python in Blender.

Thank you very much for your time answering my question!

Re: Changing material of the object via blendluxcore python script

Posted: Fri Jan 11, 2019 9:57 am
by B.Y.O.B.
The preset operator can only be used in a very specific context.

But you can see what it does internally and do something similar in your script:
https://github.com/LuxCoreRender/BlendL ... ets.py#L52

Re: Changing material of the object via blendluxcore python script

Posted: Thu Jan 17, 2019 7:39 am
by pro
Thank you very much for your help - that's excactly what I needed! :)