2
$\begingroup$

I'm trying to use prop_search to select a font that is loaded in the current blender file, similar to the example given here. The problem is I can't figure out where a collection of fonts for python to search through is. This is what I've tried.

fonts = bpy.data
col.prop_search(fonts,"BlockFont",fonts,"fonts")  
$\endgroup$
2
$\begingroup$

After a little more work I found it.

fonts = bpy.context.blend_data
scene = bpy.data.scenes['Scene']
col.prop_search(scene, "Font", fonts, "fonts")

For anyone else trying to use this, here's a quick breakdown.
The second argument is a variable to store the selected font in (see the link in the question for an example). The first argument is where blender looks for that variable (in this case, the variable was created with bpy.types.Scene.Font = bpy.props.StringProperty(), so it needed to be passed bpy.data.scenes['Scene']) . The last argument is what it populates the drop down list with, and the argument before that is where it looks for that property.
my problem was I was searching for the variable in the fonts instead of the scene where I created it, where of course it didn't exist.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.