FONT - Text from external file.

   2240   3   1
User Avatar
Member
101 posts
Joined: Sept. 2015
Offline
Hey all. I'm trying to see if it's possible load text into the “TEXT” field of the FONT node from an external text file. I didn't see anything about parsing data in this way in the manual. I've done it in other programs but just not sure if Houdini can. Anyone have a solution for this?
User Avatar
Member
359 posts
Joined: April 2017
Offline
You could use a Python expression to handle this, if you're familiar. Basically you'd add a spare parm to your Font SOP that would point to a text file, and then create a Python expression in the “Text” parameter that would load that file and return its contents, like this:

file_path = hou.pwd().parm("file_path").eval()
text = ""
with open(file_path, 'r') as f:
    text = f.read()
return text

I'm attaching a little example.

Attachments:
font_from_file.zip (9.0 KB)

MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
User Avatar
Member
101 posts
Joined: Sept. 2015
Offline
toadstorm
You could use a Python expression to handle this, if you're familiar. Basically you'd add a spare parm to your Font SOP that would point to a text file, and then create a Python expression in the “Text” parameter that would load that file and return its contents, like this:

file_path = hou.pwd().parm("file_path").eval()
text = ""
with open(file_path, 'r') as f:
    text = f.read()
return text

I'm attaching a little example.


Thank you! I will try this out.
User Avatar
Member
1737 posts
Joined: May 2006
Offline
Just updating cos I stumbled across this today, there's a helper function to read text files in directly:

hou.readFile('/Users/mestela/test.txt')

Which works directly in the text field (after you do that silly dance to keyframe the text field, then swap it to python)

Attachments:
font_sop_text_python.png (82.4 KB)

http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
  • Quick Links