ColorTool - Change colors in document, copy and paste etc.

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Fahim, Distinct Sun, Víctor Paredes, erey, Belgarath, slowtiger

ponysmasher
Posts: 370
Joined: Thu Aug 05, 2004 2:23 am
Location: Los Angeles
Contact:

ColorTool - Change colors in document, copy and paste etc.

Post by ponysmasher » Thu Dec 23, 2010 9:38 pm

I wanted a button for swapping the fill and stroke of shapes so I wrote that.
Then I wanted to be able to copy more than one fill and stroke at a time. Then I wanted to be able to replace colors in group layers.
And then in entire documents.
And then I wanted to add several other functions but here's where I've gotten so far.

Get it here: DS_ColorTool.zip

The tool is based on the select shape tool in AS pro so it has all of the same functions and you can replace it if you want.

The first button is swap. It will swap the fill and stroke of a selected shape.

Image

The second button is stroke to fill which simply sets the fill color to the same color as the stroke.

Image

The fill to stroke button does the opposite.

Image

Next we have some swatches with copy and paste buttons. These are for copying and pasting colors between shapes.
The left swatch is for fill and the right for stroke. This is used in case you want to copy more than one color from another layer, instead of copying one at a time and moving between layers you can copy three colors at once (five with the extended version of the script).

Image

These swatches also serve another purpose. We can replace colors in layers or the entire document.
Set the leftmost swatches to the fill and stroke you wish to replace and the right swatches to the new colors that you want.

Image

You can select to replace colors in the entire document or just the layer selected.

Image

If you have selected a group layer, switch layer or bone layer, the color will be changed in the child layers.

The script currently only goes four levels deep. That is it can replace the colors of a layer in a group within a group within a group. That´s four levels right?
Anyway, it will go four levels deep from the layer selected so you can always go deeper manually.

You can select to replace just fills or just strokes.

By setting tolerance you can also replace colors similar to the one you selected.

A tolerance value of one will only replace colors that match exactly and a value of 256 (the highest) will replace all colors.
For instance if I set the new stroke color to black and the tolerance to 256, all strokes will become black no matter what color they were before.

Image

With a tolerance level of say 50, only colors that are similar will be affected.

One thing you could do is to set the fill to transparent and the tolerance to 256 and you would get a document with only strokes. Not sure why you would do it, but you can!

Image

There are two versions of this script. The extended version has more swatches and is only suitable if you have a high resolution screen.
ulrik
Posts: 1075
Joined: Thu Aug 11, 2005 10:32 pm
Location: Stockholm Sweden
Contact:

Post by ulrik » Thu Dec 23, 2010 11:12 pm

Hi Ponysmasher, this is a great script/tool you have written, thank's a lot for sharing with us!! :D

and Happy Christmas to you and everybody on this forum!
F.M.
Posts: 482
Joined: Thu Nov 04, 2004 4:29 pm
Location: Between my ears

Post by F.M. » Fri Dec 24, 2010 4:30 am

Thank you very much, for sharing!
"and then Man created god!"
Rudiger
Posts: 786
Joined: Sun Dec 18, 2005 2:25 am

Post by Rudiger » Sat Dec 25, 2010 2:32 pm

Does it work with Fazek's customised tools that can select multiple shapes at once? If so, would be outstanding!
User avatar
funksmaname
Posts: 3113
Joined: Tue May 29, 2007 11:31 am
Location: Nelson, New Zealand

Post by funksmaname » Sat Dec 25, 2010 10:50 pm

Amazing, and I'm with Rudiger - if the relevant parts can be moved to fazek's tool it will be even amazing-er! :)
ponysmasher
Posts: 370
Joined: Thu Aug 05, 2004 2:23 am
Location: Los Angeles
Contact:

Post by ponysmasher » Sat Dec 25, 2010 11:05 pm

Hmm, I've had Fazek's tools installed since forever but there's no select shape tool among them. I'll have to download them again and have a look.
User avatar
funksmaname
Posts: 3113
Joined: Tue May 29, 2007 11:31 am
Location: Nelson, New Zealand

Post by funksmaname » Sat Dec 25, 2010 11:30 pm

i think you're right actually - you can select multiple shapes with the create shape or move shape/bone tools, but if you make any colour changes it only effects 1 shape of the group selected... i think I still use the bog standard shape select tool, although it would be cool to add a multi shape select/effect functionality to it.

p.s. i just discovered if you select a shape and alt click another shape with the select shape tool it copies the colours between them... (AS7)
Rudiger
Posts: 786
Joined: Sun Dec 18, 2005 2:25 am

Post by Rudiger » Sun Dec 26, 2010 5:39 am

Yeah, I think Fazek just added shape selection to the universal translate tool, so there was no need for a separate select shape tool.

I guess funksmaname request is better then. Perhaps just add multiple shape select to your modified version of the select shape tool. Then you could make it so that if no shapes are selected it acts on all shapes, but if one or more shapes are selected it only acts on them. You should then have all of your bases covered!

I have also written scripts in the past that select mutliple shapes based on selected points or point groups. You could perhaps integrate something like that into your tool as well, ie have a drop down points group list, but it selects all of the shapes that belong to the group instead of the points.
crsP
Posts: 209
Joined: Thu Apr 15, 2010 2:35 pm

Post by crsP » Tue Dec 28, 2010 2:04 pm

Hi, there is a problem with your tool.

1) Create a shape with fill and stroke
2) Add a gradient to the fill
3) Using your select shape tool, select the gradient and change the spread using the handles

Results: The gradient disappears as long as you have the mouse button held down.

Expected: The gradient preview should remain so the user can adjust it visually, just like in the lm select shape tool.
ponysmasher
Posts: 370
Joined: Thu Aug 05, 2004 2:23 am
Location: Los Angeles
Contact:

Post by ponysmasher » Tue Dec 28, 2010 6:47 pm

crsP wrote:Hi, there is a problem with your tool.

1) Create a shape with fill and stroke
2) Add a gradient to the fill
3) Using your select shape tool, select the gradient and change the spread using the handles

Results: The gradient disappears as long as you have the mouse button held down.

Expected: The gradient preview should remain so the user can adjust it visually, just like in the lm select shape tool.
That's weird since the basic function is copied directly from the original tool. I must have messed something up. Will look into it. Thanks for the feedback.
crsP
Posts: 209
Joined: Thu Apr 15, 2010 2:35 pm

Post by crsP » Mon Jan 17, 2011 10:37 pm

Hi,

Don't know if you've found the problem yet, but please could you add the box showing the shape's stack order to your tool if you can. And of course allow the user to change that order.

thanks.
crsP
Posts: 209
Joined: Thu Apr 15, 2010 2:35 pm

Post by crsP » Wed Jan 19, 2011 10:19 pm

To further explain what I mean, check out the tool mod in this thread here [second to last post on page 2]:

viewtopic.php?t=1352&postdays=0&postorder=asc&start=15
Vagabond
Posts: 106
Joined: Wed Aug 19, 2009 11:44 pm
Location: Connecticut
Contact:

Post by Vagabond » Thu Jan 27, 2011 10:28 pm

This is an incredibly useful tool. I now have a place to put my highlights, shadows, and base tones and they're just a click away. No more shape hunting and copying. And the swap feature is brillant!

Thank you
User avatar
foundmarble
Posts: 91
Joined: Fri Nov 05, 2004 12:33 am

Post by foundmarble » Thu Jan 27, 2011 11:02 pm

Great script, very useful. One request, is it possible to make the swatches smaller?
spar9zedou
Posts: 10
Joined: Tue Feb 19, 2013 12:02 pm

Re: ColorTool - Change colors in document, copy and paste et

Post by spar9zedou » Mon Feb 25, 2013 9:06 pm

You just saved me an hour. Thanks a bunch!
Post Reply