Set stroke color based on fill color.

Post questions on how to use or achieve an effect in Inkscape.
BigDumbYak
Posts: 6
Joined: Tue Dec 09, 2014 6:43 am

Set stroke color based on fill color.

Postby BigDumbYak » Tue Dec 09, 2014 6:49 am

I would like to know if it is possible to select a group of objects that have different fill colors, and have no stroke color assigned, and somehow cause each object to be assigned a stroke color that matches its fill color.

I can easily do this manually ( :tool_selector: :tool_dropper: ), but only one object at a time. When i'm working with 100+ objects, it can become a bit tedious.
I am working with data that i have imported from a bitmap tracing application, and it does not assign any stroke to the objects.

If anyone has an idea of how I can accomplish this, I would greatly appreciate it.

Thanks!

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

Re: Set stroke color based on fill color.

Postby ragstian » Tue Dec 09, 2014 7:39 am

Hi.

This can be accomplished through an extension.

Let me know how you want to use this,
do you want to select the "group of objects" or do you want the extension to work on all objects in the file?

Do you have an example file for me to work with?
Last edited by ragstian on Sat Feb 28, 2015 3:15 am, edited 1 time in total.
Good Luck!
( ͡° ͜ʖ ͡°)
RGDS
Ragnar

BigDumbYak
Posts: 6
Joined: Tue Dec 09, 2014 6:43 am

Re: Set stroke color based on fill color.

Postby BigDumbYak » Tue Dec 09, 2014 8:05 am

Ideally I'd like to be able to do this with a select group, but a whole file is just fine too if that's easier.

Here is an example of the type of data I'm working with.
https://www.dropbox.com/s/yl2uunbut2xmu ... 2.svg?dl=0

Thanks for your help!

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

Re: Set stroke color based on fill color.

Postby ragstian » Tue Dec 09, 2014 9:42 am

Hi

To get rid of the white stroke do as follows;

Select all objects; CTRL + A
Ungroup; SHIFT + CTRL + G (do this several time until there are no more groups. Check the status line at the bottom of the main Inkscape window)
Duplicate all objects; CTRL + D
Change all selected objects to paths; SHIFT + CTRL + C

Let me know if this works for you, might not be necessary to write the extension after all?
Last edited by ragstian on Sat Feb 28, 2015 3:15 am, edited 1 time in total.
Good Luck!
( ͡° ͜ʖ ͡°)
RGDS
Ragnar

BigDumbYak
Posts: 6
Joined: Tue Dec 09, 2014 6:43 am

Re: Set stroke color based on fill color.

Postby BigDumbYak » Tue Dec 09, 2014 1:01 pm

That definitely solves the visual issue, thanks Ragnar!

Although, it does double the objects involved.

I should really learn some extension scripting. How much work would it be to do that?

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

Re: Set stroke color based on fill color.

Postby ragstian » Tue Dec 09, 2014 1:24 pm

Hi
I should really learn some extension scripting. How much work would it be to do that?


It all depend on where at the moment when it comes to programming etc.
Making small scripts is fairly easy. The hard thing is to figure out where to begin
as the info on writing extensions for Inkscape seems to be scattered "all over the net".
You can use whatever language you are comfortable with, my favorite language is python, most extensions are written in python.
To get you started have a look at the extensions already included in inkscape (installdir\share\extensions )
You will find one .inx file and a scriptfile (.py for python) where the inx defines the GUI (Graphical User Interface).
Have a look at the files in your favorite text editior and go from there!
Last edited by ragstian on Sat Feb 28, 2015 3:15 am, edited 1 time in total.
Good Luck!
( ͡° ͜ʖ ͡°)
RGDS
Ragnar

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: Set stroke color based on fill color.

Postby Lazur » Tue Dec 09, 2014 9:38 pm

If you want to select all objects with the same fill attribute, inside a group,
you can use the search tab.

First, open the xml editor (Shift+Ctrl+X). With the node tool, select one object with the desired fill.
Copy the fill attribute from the xml,
then open the search tab (Ctrl+F), and paste in the right field.

Maybe it would be a good idea to ungroup all objects at the beginning.
Then, after all paths with the same fill are selected, you can combine them together (Ctrl+K).
If no strokes are set, dynamic offsetting or outsetting may fill up the gaps.

Here was a similar topic, with another solution by Grobe.

BigDumbYak
Posts: 6
Joined: Tue Dec 09, 2014 6:43 am

Re: Set stroke color based on fill color.

Postby BigDumbYak » Wed Dec 10, 2014 12:21 am

Thanks for the info Lazur URH, but I do not think this would apply to my situation very well, as there are hundreds of different fill colors involved with this image and my main goal is to add a stroke to each of them with the same color as the existing fill color.

I WILL definitely store this info for later though, as I can see places where this would be a useful technique.

kevin360
Posts: 1
Joined: Fri Dec 12, 2014 11:18 am

Re: Set stroke color based on fill color.

Postby kevin360 » Fri Dec 12, 2014 11:24 am

I'm having a similar issue and so far none of the fixes have helped. If I select a path and stroke it with a width of 0.1 set to the same color as the fill then it fixes the issue. Here's a section that shows the lines:

http://www.bluelavalamp.net/lines.svg

An extension that would set the stroke for the path based on the fill color would be great if someone can do it!

Thanks,
Kevin

tylerdurden
Posts: 2344
Joined: Sun Apr 14, 2013 12:04 pm
Location: Michigan, USA

Re: Set stroke color based on fill color.

Postby tylerdurden » Fri Dec 12, 2014 12:50 pm

kevin360 wrote:An extension that would set the stroke for the path based on the fill color would be great if someone can do it!

Agree.


Another option might be to outset all objects by 1px. My old computer chokes on the massive number of objects, but a newer one might handle it.
Have a nice day.

I'm using Inkscape 0.92.2 (5c3e80d, 2017-08-06), 64 bit win8.1

The Inkscape manual has lots of helpful info! http://tavmjong.free.fr/INKSCAPE/MANUAL/html/

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

Re: Set stroke color based on fill color.

Postby ragstian » Sat Dec 13, 2014 7:00 am

Hi.

Here are the first iteration of the extension.
setstroke.zip
(2.39 KiB) Downloaded 315 times


A few "undocumented features" (bugs) has to be worked out;

The extension does not work on groups - make sure to un-group all objects before applying the extension. - (Ungroup several times on the provided example file.)
When all objects are selected the extension does not work - select only a part (half) of the objects at a time.
(Working on this bug - examining the "structure" of the SVG file - stay tuned for update(s))

The extension is "resource hungry" - on my i7-3.3GHz it uses about a minute to go through half the objects in the example file in this thread.

This extension serves a "special purpose" and I do not see it as being useful for other than the original poster. Use at your own risk!

"Install" the extension to the user directory and NOT to the Inkscape install directory.

In Inkscape the extension can be found under "Extensions - Color - Set Stroke Color Same As Fill Color".
Last edited by ragstian on Sat Feb 28, 2015 3:14 am, edited 1 time in total.
Good Luck!
( ͡° ͜ʖ ͡°)
RGDS
Ragnar

tylerdurden
Posts: 2344
Joined: Sun Apr 14, 2013 12:04 pm
Location: Michigan, USA

Re: Set stroke color based on fill color.

Postby tylerdurden » Sat Dec 13, 2014 10:16 am

Very nice! Works well here, up to about 2000 objects.
Have a nice day.

I'm using Inkscape 0.92.2 (5c3e80d, 2017-08-06), 64 bit win8.1

The Inkscape manual has lots of helpful info! http://tavmjong.free.fr/INKSCAPE/MANUAL/html/

BigDumbYak
Posts: 6
Joined: Tue Dec 09, 2014 6:43 am

Re: Set stroke color based on fill color.

Postby BigDumbYak » Thu Feb 19, 2015 4:00 am

ragstian wrote:Hi.

Here are the first iteration of the extension.
setstroke.zip


A few "undocumented features" (bugs) has to be worked out;

The extension does not work on groups - make sure to un-group all objects before applying the extension. - (Ungroup several times on the provided example file.)
When all objects are selected the extension does not work - select only a part (half) of the objects at a time.
(Working on this bug - examining the "structure" of the SVG file - stay tuned for update(s))

The extension is "resource hungry" - on my i7-3.3GHz it uses about a minute to go through half the objects in the example file in this thread.

This extension serves a "special purpose" and I do not see it as being useful for other than the original poster. Use at your own risk!

"Install" the extension to the user directory and NOT to the Inkscape install directory.

In Inkscape the extension can be found under "Extensions - Color - Set Stroke Color Same As Fill Color".

Good Luck
RGDS
Ragnar


This is beautiful Ragnar, thanks for your assistance! I won't use it every day, but It will definitely get used a few times a month, and save me HOURS of work.

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

Re: Set stroke color based on fill color.

Postby ragstian » Thu Feb 19, 2015 7:04 am

Hi.
bigdumbyak wrote:This is beautiful Ragnar, thanks for your assistance! I won't use it every day, but It will definitely get used a few times a month, and save me HOURS of work.

Thanks for the positive feedback!
Last edited by ragstian on Sat Feb 28, 2015 3:14 am, edited 1 time in total.
Good Luck!
( ͡° ͜ʖ ͡°)
RGDS
Ragnar

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

Re: Set stroke color based on fill color.

Postby brynn » Thu Feb 19, 2015 12:41 pm

Ragnar, you should look into getting your extensions added or packed with Inkscape. Or at least included in Extensions Repository http://wiki.inkscape.org/wiki/index.php ... Repository.

Probably you'd need to subscribe to the development mailing list. But it's not so hard to do. I managed to figure it out. Or maybe you could contact developers via IRC?

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

Re: Set stroke color based on fill color.

Postby ragstian » Thu Feb 19, 2015 12:54 pm

Hi.
brunn wrote:Ragnar, you should look into getting your extensions added or packed with Inkscape. Or at least included in Extensions Repository


Thanks brynn but I don't think my extensions pass the stringent "quality control" needed for extensions to go with inkscape or to be in the repository.
I am not good at coding and based on earlier feedback I am reluctant to "step up" and present my code to the "pro's".

Still learning how the extensions works "behind the scenes" but maybe one day I will know enough to produce some "good" quality code. :)
Last edited by ragstian on Sat Feb 28, 2015 3:14 am, edited 1 time in total.
Good Luck!
( ͡° ͜ʖ ͡°)
RGDS
Ragnar

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

Re: Set stroke color based on fill color.

Postby brynn » Thu Feb 19, 2015 1:51 pm

Oh, now I understand what you mean about not being ready for developer mailing list. I understand now :D


Return to “Help with using Inkscape”