2
$\begingroup$

I'm currently working on new addon for blender 2.8 but I got stuck because I need to find a way to list all the Matcaps and Studio lights installed inside blender.

I'm using this to list all the matcaps and studioligths installed in blender:

import bpy

lights= bpy.context.preferences.studio_lights

list_lights=[]

list_lights.append(tuple(lights))  

print(list_lights)  

and It works that list all the studio ligths and matcaps, but with this structure:

<bpy_struct, StudioLight("basic_1.exr")>, StudioLight("03_Three_Points.sl")>...

and I would like to have only the name and the type of the light something like this:

['basic_1.exr'], ['03_Three_Points.sl']...

Hopefully someone could bring me some help

Thank you so much in advance

$\endgroup$
0

1 Answer 1

2
$\begingroup$

What you are seeing is the string representation of a blender class instance, for example the context scene object.

>> str(C.scene)
'<bpy_struct, Scene("Scene")>'

In this case an object of type bpy.types.StudioLight Of particular interest the name and type property.

>>> for sl in C.preferences.studio_lights:
...     sl.name, sl.type
...     
('Default', 'STUDIO')
('basic_1.exr', 'MATCAP')
('basic_2.exr', 'MATCAP')
('basic_dark.exr', 'MATCAP')
('basic_side.exr', 'MATCAP')

For example to make a dictionary with the type as the key to a list of the names of all of that type:

>>> from collections import defaultdict
>>> studio_lights = defaultdict(list)
>>> for sl in C.preferences.studio_lights:
...     studio_lights[sl.type].append(sl.name)
...     

What types are there?

>>> studio_lights.keys()
dict_keys(['STUDIO', 'MATCAP', 'WORLD'])

All those of type 'MATCAP'

>>> studio_lights['MATCAP']
['basic_1.exr', 'basic_2.exr', 'basic_dark.exr', 'basic_side.exr', 'ceramic_dark.exr', 'ceramic_lightbulb.exr', 'check_normal+y.exr', 'check_reflection.exr', 'check_rim_dark.exr', 'check_rim_light.exr', 'clay_brown.exr', 'clay_muddy.exr', 'clay_studio.exr', 'jade.exr', 'metal_anisotropic.exr', 'metal_carpaint.exr', 'metal_lead.exr', 'metal_shiny.exr', 'pearl.exr', 'resin.exr', 'skin.exr', 'toon.exr']
$\endgroup$
1
  • $\begingroup$ This help me a lot thank you so much!!!! $\endgroup$
    – alceroth
    Commented Mar 12, 2019 at 16:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .