Importing text

Post questions on how to use or achieve an effect in Inkscape.
pshute
Posts: 14
Joined: Sat Jan 05, 2013 8:52 am

Importing text

Postby pshute » Sun Jan 06, 2013 9:38 am

I need to import a lot of text from another program. They're Audacity labels - there's no chance of it having a compatible format to transfer them, so I'll have to create one.

I can export them from Audacity as a list of text stings with corresponding time ranges in seconds, e.g:

Code: Select all

98.579581   98.579581   Test text 1
158.579581   158.579581   Test text 3
218.579581   218.579581   Test text 2
278.579581   278.579581   Test text 4

I can manipulate this so that the times are the coordinates where I'd like to place each piece of text.

What are my options for getting this text into an Inkscape drawing? I read that I can run commands from the command line, and tried the --verb-list option, but it didn't list anything. Even --help doesn't work. Should I be doing something to make that work? If I can create a piece of text in a particular position from the command line then I can manipulate the file into a series of command lines.

Are there any other methods? Scripts? Macros? Try to manipulate the file into svg format?

User avatar
brynn
Posts: 10309
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: Importing text

Postby brynn » Sun Jan 06, 2013 10:41 am

Uummmm....well, this question is over my head. I'm not sure what you mean by "import text"....but I"ll be interested to find out. When you mention "time ranges" do you mean that you want to make an animation?

This probably isn't your answer, but as far as I know, you can simply copy text from wherever it is, and then paste into Inkscape. But something tells me that's not exactly what you're asking.

But, it looks like several people have been around the forum today, so maybe someone else will understand :D

pshute
Posts: 14
Joined: Sat Jan 05, 2013 8:52 am

Re: Importing text

Postby pshute » Sun Jan 06, 2013 10:47 am

Sorry, I thought that might be a bit hard to understand. I've got a text file with hundreds of short pieces of text in it, one per line. I want to get them into an Inkscape drawing somehow, each one as a separate text object. Pasting one by one isn't an option.

I can supply coordinates for each piece of text.

User avatar
ragstian
Posts: 1181
Joined: Thu Oct 11, 2012 2:44 am
Location: Stavanger-Norway

Re: Importing text

Postby ragstian » Sun Jan 06, 2013 12:14 pm

Hi.

This is typically a task where a little programming knowledge can come in handy.

Have a look at python; http://www.python.org/
I recommend sticking to the 2.7.3 version if you are planning on using it for making SVG files as there are more ready-made libraries.

Several SVG libraries exist for outputting to SVG files;
http://pypi.python.org/pypi/svgwrite/
http://pygal.org/
http://code.google.com/p/svgfig/

Another option is to use the excellent Veusz plotting package - this can import textfiles (like yours) and output to SVG or PDF files.
http://home.gna.org/veusz/
This program can look a little "overwhelming" but is quite easy to use.
Let's know if you need any further help programming python or importing into Veusz.

Good Luck
RGDS
Ragnar
Good Luck!
( ͡° ͜ʖ ͡°)
RGDS
Ragnar

Jelle
Posts: 78
Joined: Sat Nov 06, 2010 11:25 am

Re: Importing text

Postby Jelle » Sun Jan 06, 2013 8:20 pm

Hello Pshute,

I think the easiest way is to do it with a bit javascript and a browser. Just read the text file using a string function to read word by word and then add some SVG code around it, dump the result to your browser window and save it as a new svg file. That way you have a fast method to check if the result is what you want. Afterward you can edit the file with Inkscape to make it look better.

And yes,.. you can do it in Python too, but it won't give you direct result in a viewable format, so may need a little more user interaction. Javascript also gives you full access to the SVG DOM, something I haven't found a Python library for yet.

User avatar
brynn
Posts: 10309
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: Importing text

Postby brynn » Sun Jan 06, 2013 10:12 pm

Well, I certainly know nothing about coding in any language. But if the doc where the text currently resides allows a multiple selection, it could be selected all at once and pasted all at once. If the text in the other document contains only the text you need, and nothing that you don't need, Select All should work in any program that I've ever used. To my knowledge, it would be pasted as individual words.

I still don't understand how having the coordinates of the text would help. But maybe that's where the coding comes in and could be useful? I'll keep watching the comments, and maybe I'll actually learn something :lol:

pshute
Posts: 14
Joined: Sat Jan 05, 2013 8:52 am

Re: Importing text

Postby pshute » Mon Jan 07, 2013 4:30 am

brynn wrote:I still don't understand how having the coordinates of the text would help. But maybe that's where the coding comes in and could be useful? I'll keep watching the comments, and maybe I'll actually learn something :lol:

I mean that I need each piece of text to be pasted into a particular place. The coordinates specify the intended position of each piece of text. I'm investigating this Veusz program, hopefully it'll do what I want.

User avatar
ragstian
Posts: 1181
Joined: Thu Oct 11, 2012 2:44 am
Location: Stavanger-Norway

Re: Importing text

Postby ragstian » Mon Jan 07, 2013 4:55 am

Hi.

Here are a short example of a python program to do what you want:
Image

It will give the following output:
Image

The "scrambeled - out of order - text" is present in pshute's data - I don't know if it's intentional or an error.
Y position taken from the first data row in the file - ( first and second rows are identical and does not really represent a range )
The python code is not the most "pythonic" way of doing things - written to be easy to understand for a "newbie" coder!

Good Luck
RGDS
Ragnar
Good Luck!
( ͡° ͜ʖ ͡°)
RGDS
Ragnar

rich2005
Posts: 55
Joined: Fri Mar 30, 2012 9:06 pm

Re: Importing text

Postby rich2005 » Mon Jan 07, 2013 5:53 am

I can manipulate this so that the times are the coordinates where I'd like to place each piece of text.
What are my options for getting this text into an Inkscape drawing?


Does the 'plot text from CSV' extension not do this?

viewtopic.php?f=11&t=9212

User avatar
ragstian
Posts: 1181
Joined: Thu Oct 11, 2012 2:44 am
Location: Stavanger-Norway

Re: Importing text

Postby ragstian » Mon Jan 07, 2013 6:33 am

Hi rich2005
Does the 'plot text from CSV' extension not do this?

Of course it does! Easier and better! I was not aware of this extension!
Just make sure the file is 'comma delimited' - replace the two spaces in pshutes file with commas.
From this:
xxx__yyy__text1_text2_text3
to this:
xxx,yyy,text1 text2 text3

(As the forum are removing double spaces the spaces has been changed to underscores)

Good Luck!
RGDS
Ragnar
Good Luck!
( ͡° ͜ʖ ͡°)
RGDS
Ragnar

pshute
Posts: 14
Joined: Sat Jan 05, 2013 8:52 am

Re: Importing text

Postby pshute » Tue Jan 08, 2013 10:42 am

rich2005 wrote:
I can manipulate this so that the times are the coordinates where I'd like to place each piece of text.
What are my options for getting this text into an Inkscape drawing?


Does the 'plot text from CSV' extension not do this?

viewtopic.php?f=11&t=9212

Thanks, that's working well now. I read my tab separated file into Excel, set the second column to zero (it's the other end of a time range, usually the same as the first column), shifted and scaled the first column to match the scale of my drawing, and saved it in CSV format.

I had to fight Inkscape a bit, as it kept creating the text with no stroke or infill, and once or twice put it in the wrong place. I didn't get to the bottom of the latter, but it worked in the end. There's something inconsistent about using the "bottom left" origin option.

I also tried Veusz, but found that it exported the text as paths, so wasn't suitable for importing back into Inkscape.

xiox
Posts: 1
Joined: Tue Apr 09, 2013 6:59 pm

Re: Importing text

Postby xiox » Tue Apr 09, 2013 7:03 pm

I also tried Veusz, but found that it exported the text as paths, so wasn't suitable for importing back into Inkscape.

I know this is an old thread, but I thought I'd note that Veusz has an option (in Preferences) to export text as text in SVG. The default is to use paths to make it as WYSIWYG as possible.

pshute
Posts: 14
Joined: Sat Jan 05, 2013 8:52 am

Re: Importing text

Postby pshute » Wed Apr 10, 2013 7:22 am

Thanks for that. Better late than never!


Return to “Help with using Inkscape”