Jump to content

Import strings from text file


rurik

Recommended Posts

Hello

I'm trying to achieve an effect where I can copy stamp a bunch of words from a text file into a Font SOP so that I can just keep adding words to the text file and have those words appear in my particle simulation.

I'm assuming Python can help me here, does anybody have pointers to how I would go about doing that?

Thanks!

Link to comment
Share on other sites

Thanks Luke

Which node would I use to read in the text file? Sorry I'm very green with Houdini and Python...Would I be able to just use a file.open() inside the Copy SOP? Or would I need to open it elsewhere?

Thanks so much, want to figure this out but am having trouble finding out where to start

Alex

Link to comment
Share on other sites

Sure. Python, custom expression. Both work. Python is far more expansive but to be different, I used a custom in-line expression to randomly pick over some words. If it's entire sentences or paragraphs with formatting, then use Python.

In the attached example I used a variable to hold the text associated with each point and then passed that on to the Font SOP with a Copy Stamp SOP and for agruments sake, also used a For Each SOP as they are basically the same thing.

I always use ForEach SOPs these days as most Artists just don't want to wrap their heads around Copy Stamping but just want things to work. Packaging up things in to the ForEach SOP is neat, tidy and self-contained. Copy SOP on the other hand can lead to spaghetti references that can be hard to follow as you are chasing stamp() and stamps() expressions potentially all over the place. ;)

word_list_stamped_on_points.hip

  • Like 1
Link to comment
Share on other sites

Which node would I use to read in the text file? Sorry I'm very green with Houdini and Python...Would I be able to just use a file.open() inside the Copy SOP? Or would I need to open it elsewhere?

In my above example you could host the Python Code right in the Attribute Create SOP to be quick and dirty.

Another way would be to turn this in to an asset and use the asset's internal Python Module section to add your text reader in there then reference that function in the SOP network.

You can also create a net new Python SOP that hosts the code to create the string attribute that then get's expanded in the Font SOP.

Another approach is to put the Python function right in the Font SOP string field and do the work in there and just pass in the point number and bypass the point string attribute entirely. Good if you are processing millions of points. I do like to see the string right there on the point though...

Quite a few ways to do this and they are all valid and will work just fine.

  • Like 1
Link to comment
Share on other sites

@old school: I didn't know most artists preferred the ForEach SOP. Given the same functionality, using the Copy SOP should lead to faster cooking/execution times over ForEach SOP, right?

Of course I choose whichever makes more sense given the problem, which is mostly the Copy SOP for me :)

Link to comment
Share on other sites

I just realized that instead of using the script OldSchool used in the Attribcreate, I could use something as simple as `arg("THE WORDS I WANT TO USE",$PT)' and get pretty much the same result...OldSchool's method is more powerful because using the floor method or any other filtering I could selectively leave out some of the words, but this shorter expression is probably easier to remember :)

Thanks!

Link to comment
Share on other sites

  • 1 month later...

Usage

instancepoint()

This function takes no arguments. You can use this function in parameter expressions on objects being instanced (see point instancing). It returns the point number the object is being instanced onto. You can use this to vary object-level parameters (such as transforms or material overrides) between instances.

You can not use this function at the surface level, because instancing only works at the object level.

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...