Jump to content

Reading Coordinate Data(XYZ) from a .txt file into Houdini.


Barad-Dur

Recommended Posts

Hi guys,

If I had a .txt file in this format:

17.813 58.693 12.84

18.322 57.538 12.101

19.493 56.83 12.766

19.731 55.651 12.514

18.724 57.964 10.686

17.703 58.857 10.022

where first column is X, second is Y and third is Z how would I go about getting Houdini to read that data and generate a point cloud that I could use to copy geometry to etc. The above data are just a portion from a massive file of like 5000 points or so. It would seem that this would be a good spot to get Houdini to simply read a file from a file SOP and dump these XYZ data into an Add SOP or something akin to that.

Any advice on this would be most appreciated. Thanks

David

Link to comment
Share on other sites

This is something that could easily be accomplished using a simple Python Sop.

Something like this should work as long as you have added a File parameter named 'file' to your operator.

Note: Make sure the File parameter is a standard File, as Geometry - File would set a file type filter on the chooser and you would have to set it to * to see your .txt file.

geo = hou.pwd().geometry()

filepath = hou.pwd().parm('file').eval()

positions = hou.readFile(filepath)

for line in positions.splitlines():
	if line == '':
		continue
	pos = line.split() 

	x = float(pos[0])
	y = float(pos[1])
	z = float(pos[2])
	point = geo.createPoint()

	point.setPosition((x,y,z))

You could also look at writing a simple converter that could convert your .txt file into a .geo file.

Edited by graham
Link to comment
Share on other sites

Rename your file so that it has a .chan as the file extension. Put down a File CHOP and reference your file. Append a Rename CHOP to this and rename the channels to "tx ty tz". Now use a Channel SOP to reference your CHOP. Here's an example file and I've locked the File CHOP so that it's all contained in one file.

posFromFile.hipnc

Link to comment
Share on other sites

  • 12 years later...
On 11/16/2008 at 2:59 AM, graham said:

This is something that could easily be accomplished using a simple Python Sop.

Something like this should work as long as you have added a File parameter named 'file' to your operator.

Note: Make sure the File parameter is a standard File, as Geometry - File would set a file type filter on the chooser and you would have to set it to * to see your .txt file.

 


geo = hou.pwd().geometry()

filepath = hou.pwd().parm('file').eval()

positions = hou.readFile(filepath)

for line in positions.splitlines():
	if line == '':
		continue
	pos = line.split() 

	x = float(pos[0])
	y = float(pos[1])
	z = float(pos[2])
	point = geo.createPoint()

	point.setPosition((x,y,z))
 

 

You could also look at writing a simple converter that could convert your .txt file into a .geo file.

Hi Graham.

just wondering,
Do you have code to write to disk Point cloud Data with Pos and Color attribute to txt ?

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