Color replace one palette with another?



  • Hey there, I've got a workflow wherein I take an SVG with up to 30 colors and replace those colors with a specific color palette.

    For example, take a grayscale heightmap convert it to SVG using at most 30 colors. This gives me a document with 30 slight variations of gray.
    I have a specific color palette for some laser software (lightburn) which has 30 colors as well.

    I would like to map the colors in the document directly to colors in the lightburn color palette. The colors in the document don't actually matter, just that they are unique. This means I have a bit of strange usecase where I don't care about "nearest color" or anything like that.
    Ideally the workflow would be:
    Open SVG in vectorstyler
    Select all colors in document (this will be max 30 because of the method of generation)
    Replace those document colors with colors from my lightburn color palette.
    Modify my svg knowing that my export will "just work" with my laser software because all of the colors match up šŸ™‚

    I've looked at replace colors but I just can't wrap my head around it after an hour or so of playing with it.
    My only other solution is to write a little script that iterates through all elements of a given svg and replaces unique rgb values. Which isn't terrible but if it's possible in the software I'd rather do it there.

    (thanks for reading my wall of text!)



  • Welcome to VectorStyler!

    Are the colors in the SVG files the same all the time?

    If they are, it can be done ā€” I would use 'Save Selection' and Actions like this:

    1. Prepare the "master" document

    • open/import/drag one of the SVG to the artboard;

    • ungroup it;

    • create 30 rectangles/shapes each with its stroke in the initial colors found in
      the SVGs you need to edit (and maybe move them outside the artboard);

    • select each one and save it as a selection in the Selections panel (Panels > Editing >
      Selections) by clicking the [+] button at the bottom of the panel;

    • when finished, save the file (File > Save).

    2. Record an action:

    • open the Actions panel (Panels > Presets > Actions);

    • click the third button at the bottom of the Actions panel, to create a new action;

    • give it a name (Color Replacer' maybe);

    • click OK, which now starts recording;

    • go to the Select menu > Markers, and click the first saved selection from the list;

    • go to the same Select menu > Select by Style and choose 'Stroke Style';

    • now all the objects that have the same stroke color should be selected;

    • choose another stroke color for them by Option-clicking another color from
      your (custom?) color palette;
      ā€¦ā€¦
      ā€¦
      ..
      Repeat these four steps with the other 29 objects and when finished, choose 'Deselect'
      from the 'Select' menu and stop the recording with the same button in the Actions panel.

    Once edited, just move the objects of the SVG to another document (Edit > Cut), and you can
    use this action in combination with this document (you bring another SVG into it) to
    change its colors.



  • @heuristicbishop Here's a short demonstration: https://recordit.co/I4k5DH2s2B


  • administrators

    @heuristicbishop Do you need every gray level uniquely assigned to another color? (mapping 30 grays to 30 colors)

    replace color cannot do this (for now), maybe this could be a new feature in the (near) future.



  • @VectorStyler Correct, a direct mapping of 30 unique grayscale in the document -> 30 unique colors from my palette would be ideal.

    I was thinking most of the bits are already in place for this sort of thing. Super cool to hear that it might be possible in the (near) future even šŸ™‚
    I'll get a few screenshots together to show exactly what I'm trying to do here. For my test doc I'll just do the color replace manually so you can see exactly what I'm going for.

    This kind of developer interaction is what brought me to vectorstyler from inkscape šŸ™‚
    (Can't wait for a proper API to play with so I can whip up my own silly plugins!)



  • @b77 The colors will likely change from doc to doc for now but this was still super helpful. I'll be on the lookout for how I can implement actions going forward.

    Really appreciate you taking the time to write it up and going the extra mile to do a recording. Fixing a typo mid-recording, now that's dedication to perfection šŸ˜Ž



  • @heuristicbishop said in Color replace one palette with another?:

    @b77 The colors will likely change from doc to doc

    Since plugin support is not coming next week (AFAIK), if you know regular expressions
    you can open the SVG in a text editor like BBEdit, which has a powerful regex engine
    and can record scripts as AppleScripts.

    You just need to know regular expressions well enough so that the search expression
    finds all the colors that meet a certain criteria, then replacing them is easy.


  • administrators

    @heuristicbishop said in Color replace one palette with another?:

    Can't wait for a proper API to play with so I can whip up my own silly plugins!

    VS can save its document in XML or JSON formats (Document Setup -> File -> File Format), that can be then manipulated with external scripts / tools.