Jump to content

Reading A Text File


Recommended Posts

Hello,

Basically, I am trying to copy/stamp random words onto points. I would like to import the words that will be stamped from an external text file. Is there a way to read an external .txt file into a string variable?

Thanks.

Link to comment
Share on other sites

On Unix, you can probably do:

set text = `system("cat myfiles.txt")`

Thanks a lot Edward!

That worked perfectly. I put this string of code into my Font SOP text field and it read the contents of my file. Thanks again.

`arg(system("cat ../scripts/my_text.txt"), stamp("../copy1", "wordnum", 0))`

Link to comment
Share on other sites

  • 11 months later...

Just to bring up the old topic back, I was wondering if the expression works in PC, under Windows XP? I mean this one: `system("cat myfiles.txt")`? I am not quite understand the 'cat` thing.

As well to expand the question, instead of manipulating "string" how would it be possible to convert the string back into numbers to further manipulate them into pattern, etc?

- enzym

Link to comment
Share on other sites

Cheers for the tips Kubabuk, I'll see to that. The `cat` command thing is interesting.

Just wondering if there is a simpler solution using network nodes alone to bring some text (*.txt) in.

- Zyme

Link to comment
Share on other sites

I had recently good results by using a python function:

The function builds a dictionary from a given text file.

In the fontSOP a python expression queries the dictionary.

Link to comment
Share on other sites

  • 1 year later...

Hi Georg,

Reviving this topic again.

I was wondering if by chance you (or anyone else) could share that python fuction ? That would be really helpfull.

In the meantime I'll try the cygwin way.

br1

Link to comment
Share on other sites

I was wondering if by chance you (or anyone else) could share that python fuction ? That would be really helpfull.

The mysterious function looks like this:

http://www.google.com/search?q=read+file+python

Link to comment
Share on other sites

There's also hou.readFile() that supports regular files, opdef and oplibs.

an example would be great. I'm lost ...

I'm trying hou.readFile("e:/test/test.txt") but it returns errors, I guess I'm doing it wrong.

error message : OperationFailed : The attempted operation failed.

Edited by br1
Link to comment
Share on other sites

an example would be great. I'm lost ...

I guess it really depends on what you are trying to archive as this determines what function would need to go where ...

but usually something like:

f = '/me/you/we.txt'

hou.session.myfile = open(f, 'r').readlines()

does the job.

Somewhere else you would access hou.session.myfile based on the conditions ...

I read in the font index file and randomized the fotn type in a fontSOP that way.

Link to comment
Share on other sites

  • 2 weeks later...

I guess it really depends on what you are trying to archive as this determines what function would need to go where ...

but usually something like:

f = '/me/you/we.txt'

hou.session.myfile = open(f, 'r').readlines()

does the job.

Here are the details about what I am trying to do.

I want a lot of words to be animated around a rotating object. I use a copy sop to put all my words onto the points of a cylinder and animate that cylinder with some noise.

The problem is that all those words are not confirmed yet and are most likely to change later in the production process, so I thought it would be easier to read them from a text file. So I made a text file with each word on a separate line, and I am now trying to have each word stamped randomly or sequentially onto my cylinder.

Thanks to your explanation I can import my file in Houdini, but I don't know how to actually connect it's content to my font sop.

I hope it's a bit more clear now, thanks for your help !

Br1

Link to comment
Share on other sites

On Unix, you can probably do:

set text = `system("cat myfiles.txt")`

Thanks a lot Edward!

That worked perfectly. I put this string of code into my Font SOP text field and it read the contents of my file. Thanks again.

`arg(system("cat ../scripts/my_text.txt"), stamp("../copy1", "wordnum", 0))`

Thats exactly what I was doing was copying a different word from the text onto a point. Its a bit hazey since i did this a couple years ago, but I think that I needed to have all the words on a single line with a space separated. I cant remember what the variable "wordnum" was that was being stamped, but im guessing it was something like

$PT % (total number of words in text)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...