Sub ApplyRandomCMYKColors()
Dim s As Shape Dim color As CMYKColor
For Each s In ActiveSelectionRange ' Generate random CMYK values within a specified range Set color = New CMYKColor color.Cyan = Rnd() * 100 color.Magenta = Rnd() * 100 color.Yellow = Rnd() * 100 color.Black = Rnd() * 100
' Apply the random color to the selected object's fill s.Fill.UniformColor = color Next s
End Sub
My code in c#, tested
[CgsAddInMacro] public void ApplyRandomCMYK() { ShapeRange sr = corelApp.ActiveSelectionRange; sr.ApplyUniformFill(corelApp.CreateCMYKColor(0, 0, 0, 0)); Random rd = new Random(); corelApp.Optimization = true; for (int i = 1; i <= sr.Count; i++) { sr[i].Fill.UniformColor.CMYKCyan = rd.Next(100); sr[i].Fill.UniformColor.CMYKMagenta = rd.Next(100); sr[i].Fill.UniformColor.CMYKYellow = rd.Next(100); sr[i].Fill.UniformColor.CMYKBlack = rd.Next(100); } corelApp.Optimization = false; corelApp.Refresh(); }
Converted to VBA by ChatGPT, not tested
Sub ApplyRandomCMYK() Dim sr As ShapeRange Set sr = ActiveSelectionRange
sr.ApplyUniformFill CreateCMYKColor(0, 0, 0, 0) Dim rd As Object Set rd = CreateObject("Scripting.Dictionary")
' Seed the random number generator rd.Add "seed", GetTickCount Randomize rd("seed")
Application.Optimization = True Dim i As Integer For i = 1 To sr.Count sr(i).Fill.UniformColor.CMYKCyan = Int((100 * Rnd) + 1) sr(i).Fill.UniformColor.CMYKMagenta = Int((100 * Rnd) + 1) sr(i).Fill.UniformColor.CMYKYellow = Int((100 * Rnd) + 1) sr(i).Fill.UniformColor.CMYKBlack = Int((100 * Rnd) + 1) Next i Application.Optimization = False Application.RefreshEnd Sub
Wow, Working brother. So nice of you
Sub RandomCYANColors() Dim s As shape Dim c As Color Dim randomC, randomM, randomY, randomK As Integer Dim selectedShapes As shapes
' Get the selected shapes Set selectedShapes = activeSelection.shapes ' Loop through each selected shape For Each s In selectedShapes ' Generate random CMYK values randomC = Int((100 - 0 + 1) * Rnd + 0) ' Create a new CMYK color Set c = CreateColor() c.CMYKAssign randomC, randomM, randomY, randomK ' Set the shape fill color s.Fill.ApplyUniformFill c Next sEnd Sub
...............
Sub RandomMAGENTAColors() Dim s As shape Dim c As Color Dim randomC, randomM, randomY, randomK As Integer Dim selectedShapes As shapes
' Get the selected shapes Set selectedShapes = activeSelection.shapes ' Loop through each selected shape For Each s In selectedShapes ' Generate random CMYK values randomM = Int((100 - 0 + 1) * Rnd + 0) ' Create a new CMYK color Set c = CreateColor() c.CMYKAssign randomC, randomM, randomY, randomK ' Set the shape fill color s.Fill.ApplyUniformFill c Next sEnd Sub
Sub RandomYELLOWColors() Dim s As shape Dim c As Color Dim randomC, randomM, randomY, randomK As Integer Dim selectedShapes As shapes
' Get the selected shapes Set selectedShapes = activeSelection.shapes ' Loop through each selected shape For Each s In selectedShapes ' Generate random CMYK values randomY = Int((100 - 0 + 1) * Rnd + 0) ' Create a new CMYK color Set c = CreateColor() c.CMYKAssign randomC, randomM, randomY, randomK ' Set the shape fill color s.Fill.ApplyUniformFill c Next sEnd Sub
.....................
Sub RandomBLACKColors() Dim s As shape Dim c As Color Dim randomC, randomM, randomY, randomK As Integer Dim selectedShapes As shapes
' Get the selected shapes Set selectedShapes = activeSelection.shapes ' Loop through each selected shape For Each s In selectedShapes ' Generate random CMYK values randomK = Int((100 - 0 + 1) * Rnd + 0) ' Create a new CMYK color Set c = CreateColor() c.CMYKAssign randomC, randomM, randomY, randomK ' Set the shape fill color s.Fill.ApplyUniformFill c Next sEnd Sub
.............
Brother please update these C / M / Y / K Random colours. i got these using the chatgpt also. these are not upto my expectations, working.... but not the expected, please update brother
.
It is not very simple to generate shades of a certain color randomly
So nice of your brother. Outline colors are now working
Pick Tool + Freehand tool Toggle, brother please help this to toggle