Jump to content

File Convertion Scripting


peliosis

Recommended Posts

I have some pointcloud data from custom 3d scanner in a text file.

I need to import it into houdini as geo, but there are a few things to do:

-Change all colons to spaces

-Add "1" at the end of ech line (homogenous coords?)

-Count the nr of lines and put it in "points:..."

-Replace head and tail of the file

Perhaps some other also but marginal.

Because there are 370 000 of points / lines in the file it takes days in wordpad/jedit/crimson editor to just add "1".

I think of learning some scripting language and chose python, since it looks the easiest and the most versatile.

I work under linux, for a year now and would like to learn one language firmly to fill most of my needs.

But It's only one day since I started learning it :D

I have some experience with jscript and vbscript with xsi but nothing externally.

I search for the easiest method of such simple file convertion.

Do you think python is the right choice or perhaps should I stick to bash scripting or perhaps there is yet easier way to attack my problem?

Link to comment
Share on other sites

Thanks Simon,

I read all file object reference in the documentation and tutorial before posting this.

Not that I understand how to use it all from where I stand :).

I have some troubles in cycling the lines

for line in f:

f.write('1')

adds one "1" at the end of the file...probably not surprisingly.

I know it's only a matter of time for me to get there. Unfortunatly learning python is doomed to be my overnight hobby so I have limited hour pack and falling eyelids as my classmates.

I'd like only to know if python is a good language to start.

Of course if you'd find a sec and write something to correct me I'd be very grateful.

I really appreciate your help and time you take to answer all of us greenhorns,

that motivates me to work harder.

Link to comment
Share on other sites

I have some pointcloud data from custom 3d scanner in a text file.

I need to import it into houdini as geo, but there are a few things to do:

-Change all colons to spaces

-Add "1" at the end of ech line (homogenous coords?)

-Count the nr of lines and put it in "points:..."

-Replace head and tail of the file

Perhaps some other also but marginal.

Because there are 370 000 of points / lines in the file it takes days in wordpad/jedit/crimson editor to just add "1".

I think of learning some scripting language and chose python, since it looks the easiest and the most versatile.

I work under linux, for a year now and would like to learn one language firmly to fill most of my needs.

But It's only one day since I started learning it  :D

I have some experience with jscript and vbscript with xsi but nothing externally.

I search for the easiest method of such simple file convertion.

Do you think python is the right choice or perhaps should I stick to bash scripting or perhaps there is yet easier way to attack my problem?

25178[/snapback]

Use a real editor :-)

In Vim:

:1,$s/:/ /g

will replace all : with a space.

:1,$s/$/ 1

will add a 1 to the end of all the lines

:!wc -l %

will count your lines for you

Then, it's a matter of adding the appropriate header/trailer. Of course, you could do it with python too. And if you had a lot of files to convert, python/perl/php would probably be a better route.

Link to comment
Share on other sites

Ah that vim thing, I'm still very stubborn because it's so freakin' odd!

I'd better get to like it, once while repairing the system, my favourite pico was just not there :).

Thanks, I'll check how it processes my 372 000 of lines.

I'll need both python and vim anyway.

Link to comment
Share on other sites

Thanks, I'll check how it processes my 372 000 of lines.

25217[/snapback]

My guess is very slowly. I just wrote a a script in perl script similar to what you are trying to do, for work. It takes about 5 full minutes process 100,000 lines. I expect VIM will take quite a bit longer than that to process ~400,000 lines.

Link to comment
Share on other sites

My guess is very slowly. I just wrote a a script in perl script similar to what you are trying to do, for work. It takes about 5 full minutes process 100,000 lines. I expect VIM will take quite a bit longer than that to process ~400,000 lines.

25222[/snapback]

I hope "quite a bit" will still be shorter than 2 days in windows editors mentioned :)

It took some furious amount of time and was slowing progressively when the line nr advanced.

Horrible.

Link to comment
Share on other sites

I hope "quite a bit" will still be shorter than 2 days in windows editors mentioned :)

It took some furious amount of time and was slowing progressively when the line nr advanced.

Horrible.

25223[/snapback]

I am agree with Mcronin, a perl or python script will do the job faster.

For this situation i would use sed.

It is an inline editor and is very, very faster doing string substitution, and the syntax is very similar to Perl.

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