Change Color by Id / Name

Discussion about writing code for Inkscape.
bernie70
Posts: 6
Joined: Mon May 06, 2013 4:43 pm

Change Color by Id / Name

Postby bernie70 » Mon May 06, 2013 4:58 pm

Hello,

I have an inkscape file with many symbols on it. Some of them are shapes.

When I select one or more shapes and I use the Extension "Color" - "Color replace" I can change the color without problems.

What I need is this:

- The shapes have unique Id's/names (A01, A02, S01, S02, ...) in a own Layer
- I have a text-file which contains Ids and Colors (A01 0000FF) of the shapes in separate lines
- I want an extension which reads the textfile and changes the color of the read id to the (in the textfile) defined color.

How can I do this?

Kind regards,
bernie70
Last edited by bernie70 on Wed May 08, 2013 5:34 pm, edited 1 time in total.

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

Re: Change Color by Id / Name

Postby ragstian » Wed May 08, 2013 9:36 am

Hi.

One way to accomplish this would be through a script.
Python is my language of choice, but you could use a utility like grep (linux-unix) - wingrep (Win) or any language capable of reading and writing text-files.

Can you supply example files for us to work from?
We might be able to "hack together" a solution.

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

bernie70
Posts: 6
Joined: Mon May 06, 2013 4:43 pm

Re: Change Color by Id / Name

Postby bernie70 » Wed May 08, 2013 5:18 pm

Hi Ragnar,

thank you for the answer. I created a sample testfile to show you what I want.

In the example.svg there are the shapes like in my original-svg. The colors can always be different (yellow, red, blue). In the example.txt there are the colors to which the shapes should be changed with the extension.

Kind regards,
bernie70
Attachments
example.zip
Zip-File contains example.svg and example.txt
(1.43 KiB) Downloaded 345 times

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

Re: Change Color by Id / Name

Postby brynn » Thu May 09, 2013 1:48 am

We might be able to "hack together" a solution.

"We..." :lol:

Welcome to the forum, bernie70 :D

atomissant
Posts: 2
Joined: Fri Mar 22, 2013 6:03 pm

Re: Change Color by Id / Name

Postby atomissant » Thu May 09, 2013 5:49 am

Hello

You could try this enclosure; tested on debian.

Voilà!
Attachments
readfile.zip
Read File
(1003 Bytes) Downloaded 400 times

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

Re: Change Color by Id / Name

Postby ragstian » Fri May 10, 2013 3:14 am

Hi Bernie70

Another approach - not as elegant as atommisant's;
To use:
- save the attached file to a temporary place
- unzip and then place the two unpacked files in your "Local" extension directory - mine is on Win7; "C:\Users\Ragnar\AppData\Roaming\inkscape\extensions"
- restart Inkscape;
- find extension under; Extensions - Bernie70

Extension will ask for input data file name (File with ID and corresponding fill color);
Extension will only change selected items. (Select before running extension :) )
Extension removes stroke - like "atommisant's" extension - chime back if this is not wanted.
Extension will most likely not be very useful for anyone else than Bernie70 -
____ ( Unless you got similar color changing tasks based on a CSV (comma separated value) file. )

- brynn;
"We..." :lol:

Thanks atommisant - (Just what the doctor ordered ! At the right time! )
Yes "we" - the users of the forum!

Zip file - tested on Win7;
Bernie70.zip
(1.51 KiB) Downloaded 353 times

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

bernie70
Posts: 6
Joined: Mon May 06, 2013 4:43 pm

Re: Change Color by Id / Name

Postby bernie70 » Mon May 13, 2013 5:14 pm

Hi atomissant, hi ragstian,

thank you for your answers.

I tried your extensions and both are working fine. Thank you very much for the solutions. Now I have to decide, which version I will use :D

Kind regards,
bernie70

bernie70
Posts: 6
Joined: Mon May 06, 2013 4:43 pm

Re: Change Color by Id / Name

Postby bernie70 » Mon May 13, 2013 6:40 pm

Hi atomissant, hi ragstian,

now I have seen, that the size (width and heigth) of the modified nodes is modified a little bit after executing the extension.

Is it possible to leave the size untouched or how can I change the size of the node with the extension?

Kind regards,
bernie70

bernie70
Posts: 6
Joined: Mon May 06, 2013 4:43 pm

Re: Change Color by Id / Name

Postby bernie70 » Tue May 14, 2013 4:46 am

Hi,

I could solve the problem myself with with node.set(*width', ...) and node.set('height', ...)

Greetings,
bernie70

sudomark3
Posts: 1
Joined: Wed Oct 16, 2013 9:37 pm

Re: Change Color by Id / Name

Postby sudomark3 » Sat Oct 19, 2013 10:05 pm

You can use Python can be termed as best choice and don't forget to use a utility like grep (linux-unix) - wingrep (Win) or any language.


Return to “Programming”