Changing material of the object via blendluxcore python script

Use this forum for general user support and related questions.
Forum rules
Please upload a testscene that allows developers to reproduce the problem, and attach some images.
Post Reply
pro
Posts: 23
Joined: Wed Dec 12, 2018 7:48 am

Changing material of the object via blendluxcore python script

Post 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!
User avatar
B.Y.O.B.
Developer
Developer
Posts: 4146
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: Changing material of the object via blendluxcore python script

Post 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
pro
Posts: 23
Joined: Wed Dec 12, 2018 7:48 am

Re: Changing material of the object via blendluxcore python script

Post by pro »

Thank you very much for your help - that's excactly what I needed! :)
Post Reply