I have 6 logo i want to random arrange the logo 6 vertical x 6 horizontal. Is there any macro or way to auto arrange the logo's. Any suggestion or help. Thx
[CgsAddInMacro] public void RandomOrder() { //Number of columns and rows, can be changed to any value > 0 int cols = 6, rows = 6; //Initial position, can be changed to any position, //remember to use the same value in the column loop double posX = 0, posY = 0; ShapeRange logos = corelApp.ActiveSelectionRange; logos.Sort("@shape1.width > @shape2.width"); double width = logos[1].SizeWidth; logos.Sort("@shape1.height > @shape2.height"); double height = logos[1].SizeHeight; Random random = new Random(); for (int i = 0; i < cols; i++) { for (int j = 0; j < rows; j++) { Shape shape = logos[random.Next(1,logos.Count+1)].Duplicate(); shape.CenterX = posX + width / 2; shape.CenterY = posY + height / 2; posX = posX + width; } posY = posY + height; posX = 0; } logos.Delete(); }
can u plz show demo how it works?
I have 6 color squares, selected all the 6 colors and pasted the script and hit play why its asking to select macro, why its not play direct
Sorry, you asked for an example or an idea, this code is in C#, I know that almost no one uses C#, to use it you need to create a macro for "Visual Studio Tools for Applications", I can always easily convert from C# to VBA in ChatGPT, but this is not working.
I think this is the equivalent in VBA
Sub RandomOrder() ' Número de colunas e linhas, pode ser alterado para qualquer valor > 0 Dim cols As Integer, rows As Integer cols = 6 rows = 6 ' Posição inicial, pode ser alterada para qualquer posição, ' lembre-se de usar o mesmo valor no loop de coluna Dim posX As Double, posY As Double posX = 0 posY = 0
Dim logos As ShapeRange Set logos = ActiveSelectionRange
logos.Sort "@shape1.width > @shape2.width" Dim width As Double width = logos(1).SizeWidth
logos.Sort "@shape1.height > @shape2.height" Dim height As Double height = logos(1).SizeHeight
Dim shape As shape For i = 1 To cols For j = 1 To rows ' Obtém um índice aleatório do array Dim randomIndex As Integer randomIndex = Int((logos.Count) * Rnd) + 1 ' Duplica o shape no índice aleatório Set shape = logos(randomIndex).Duplicate shape.CenterX = posX + width / 2 shape.CenterY = posY + height / 2 posX = posX + width Next j posY = posY + height posX = 0 Next i ' Deleta os shapes originais logos.DeleteEnd Sub
when i try to change the value
cols = 5 rows = 5
getting error
works with any value > 0
getting the above error