I did an Image Trace in Adobe Illustrator and saved it as an SVG. The trace was restricted to a palette of just 6 colors. But upon importing into Blender, I end up with a separate material for each island, which in this case is hundreds of objects titled incrementally such as SVGMat.820
Up to this point, whenever I imported SVG data into Blender, it was simpler geometry, maybe a logo or something. So I just replaced the default SVG import materials with my own, maybe sampling the hex colors where relevant, and throwing away the rest.
But this time I want to keep that palette of 6 colors and just modify the shader data (I mean send unique material colors from RGB Nodes into a shared Group Node containing the shader setup - do you follow?). Unfortunately Blender has no idea that some of those materials share a common color, while others do not. And I don't feel like pasting that Group Node into 820+ separate materials! lol
Is there a way this can be tackled using Python to loop through all materials named SVGMat.*
check if the Diffuse Color matches an existing material's Diffuse Color, and if it does, discard that redundant material in favor of the existing one?
(I feel like ideally the option to restrict materials to unique colors ought to be included as a setting of the SVG importer, possibly as default, but for now any kind of scripting workaround would be awesome.)
1
Go to Layer > Layers & Objects2
Create a layer for each color to keep paths in order.3
Select the topmost layer in the stack, then Edit > Select Same... Fill Color, and drag those selected paths into the topmost Layer.4
Repeat step 3, selecting the topmost path, but move to the next layer down. Do this for ea. color.5
For ea. Layer, select the range of all paths inside, then Path > Union6
Save As $\endgroup$