How to get all colors used in document except searching by layer? Searching every layer costs too much time when the document is large. Is there any better way?
Unfortunately I don’t think so. You can get Assests like document colors and whatnaught really easily but if you want all colors used in a document I believe you will need to loop through all the layers like this:
https://github.com/Ashung/Automate-Sketch/blob/2803e2d10bdaeec8b2dd0e8c9337f63ccbb50ca2/automate-sketch.sketchplugin/Contents/Sketch/Layer/Select_or_Remove_All_Transparency_Layers.js#L107
or use Sketch.find in a clever way https://developer.sketch.com/reference/api/#find
There might be some way to hook into some private methods like MSColorReplacement or something but I’m not too sure https://github.com/abynim/Sketch-Headers/blob/382beaa961f3f1bc4e1abbeca40bc1333176bc83/Headers/MSColorReplacement.h