SpencerL Posted June 19, 2007 Share Posted June 19, 2007 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. Quote Link to comment Share on other sites More sharing options...
edward Posted June 19, 2007 Share Posted June 19, 2007 On Unix, you can probably do: set text = `system("cat myfiles.txt")` Quote Link to comment Share on other sites More sharing options...
SpencerL Posted June 19, 2007 Author Share Posted June 19, 2007 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))` Quote Link to comment Share on other sites More sharing options...
enzym Posted June 7, 2008 Share Posted June 7, 2008 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 Quote Link to comment Share on other sites More sharing options...
kubabuk Posted June 7, 2008 Share Posted June 7, 2008 Try staring H from cygwin. When it comes to cat and other unix stuff this is always a good starter: http://en.wikipedia.org/wiki/Cat_%28Unix%29 Quote Link to comment Share on other sites More sharing options...
enzym Posted June 7, 2008 Share Posted June 7, 2008 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 Quote Link to comment Share on other sites More sharing options...
rdg Posted June 9, 2008 Share Posted June 9, 2008 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. Quote Link to comment Share on other sites More sharing options...
br1 Posted July 17, 2009 Share Posted July 17, 2009 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 Quote Link to comment Share on other sites More sharing options...
rdg Posted July 17, 2009 Share Posted July 17, 2009 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 Quote Link to comment Share on other sites More sharing options...
br1 Posted July 17, 2009 Share Posted July 17, 2009 I forgot to mention that : br1.phyton.knowledge == 0 for the moment.... I'll have a look at your google link. thanks Quote Link to comment Share on other sites More sharing options...
graham Posted July 17, 2009 Share Posted July 17, 2009 There's also hou.readFile() that supports regular files, opdef and oplibs. Quote Link to comment Share on other sites More sharing options...
br1 Posted July 17, 2009 Share Posted July 17, 2009 (edited) 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 July 17, 2009 by br1 Quote Link to comment Share on other sites More sharing options...
rdg Posted July 18, 2009 Share Posted July 18, 2009 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. Quote Link to comment Share on other sites More sharing options...
br1 Posted July 28, 2009 Share Posted July 28, 2009 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 Quote Link to comment Share on other sites More sharing options...
SpencerL Posted July 28, 2009 Author Share Posted July 28, 2009 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) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.