5
$\begingroup$

How can I get / read the font used in the String to Curves node using Python?

Example:

The output I'm trying to get back from the image below would be wmcorners2 Regular:

Image 1

I know I can get a value using the code below, but how can I do this for the String to Curves node?

import bpy

# Get the node
node = bpy.data.materials["MyMaterial"].node_tree.nodes["MyNode"]

# Get the value of the first output
value = node.outputs[0].default_value

print(value)

The great answer given below by Muzammil and Chris seems to get the first font in the list not the currently selected / used font. Is there a workaround or is this a bug?

Image 2

$\endgroup$

1 Answer 1

7
$\begingroup$

This is how you can get it.

import bpy

# Reference the node group
geometry_node = bpy.data.node_groups['Geometry Nodes']

# Reference the String to Curves node
curve_node = geometry_node.nodes['String to Curves']

# Get the font
font = curve_node.font
print(font)
# Get the font name
print(font.name)
$\endgroup$
2
  • $\begingroup$ This seems to get the first font in the list not the currently selected / used font is there a workaround or is this a bug? See image in question. Should this be another question? $\endgroup$
    – Still
    Jan 26, 2023 at 7:21
  • 2
    $\begingroup$ @Still seems to be a problem on your end, I just tested and it does work correctly. Please make sure the node you're fetching matches the exact name in the code. If you have more than one "String to Curves" node in your GN tree, the second one will be automatically renamed String to Curves.001 for example $\endgroup$
    – Gorgious
    Jan 26, 2023 at 9:59

You must log in to answer this question.

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