Hello, wondering if it is possible to get some help creating a macro that groups objects based on where they are located on the page.
My document size is 24 inches wide X 18 inches high and I need to make 4 groups of objects:
The first group with all the objects/shapes found on the left 6.5 inches of the page.
Second Group with all the objects/shapes found on the section between 6.5 and 12 inches of the page.
Third Group with all the objects/shapes found on the section between 12 and 17.5 inches of the page.
and a 4th group with all the objects/shapes found between 17.5 and 24 inches of the page.
This is for laser engraving, we use CorelDraw X6 and have to do this process manually every time going trough more than 100 pages each time. Very time consuming.
This macro ideally should run through all the pages in the document.
Help with this will be greatly appreciated.
Jose
This is one of the possible solutions to your problem, use the logic to implement it in VBA if applicable, in this example it is written in C#, but I used Corel x8, I don't have x6, there may be something that doesn't work, like here community.coreldraw.com/.../api the minimum version for consultation is X7, you or someone needs to test on X6
[CgsAddInMacro] public void GroupByRegion() { double[] increments = { 6.5, 5.5, 5.5, 6.5 }; double increment; corelApp.EventsEnabled = false; corelApp.Optimization = true; corelApp.ActiveDocument.BeginCommandGroup("group"); for (int i = 1; i <= corelApp.ActiveDocument.Pages.Count; i++) { increment = 0; for (int j = 0; j <increments.Length; j++) { corelApp.ActiveDocument.Pages[i].SelectShapesFromRectangle( corelApp.ActiveDocument.Pages[i].LeftX + increment, corelApp.ActiveDocument.Pages[i].TopY, corelApp.ActiveDocument.Pages[i].LeftX + (increment += increments[j]), corelApp.ActiveDocument.Pages[i].BottomY, false).Group(); } } corelApp.ActiveDocument.EndCommandGroup(); corelApp.EventsEnabled = true; corelApp.Optimization = false; corelApp.Refresh(); }
Try this in VBA Sub FourGroupsEachPage() Dim d As Document, p As Page, s As Shape Dim x1 As Double, x2 As Double, i% Set d = ActiveDocument For Each p In d.Pages For i = 1 To 4 x1 = Choose(i, 0, 6.5, 12, 17.5, 24) x2 = Choose(i + 1, 0, 6.5, 12, 17.5, 24) Set s = p.SelectShapesFromRectangle(x1, p.BottomY, x2, p.TopY, False).Group Next i Next pEnd SubI have many laser engraving clients. Write to me at tv.softlv@gmail.com if you need anything else.Taras
Thank you so much. This worked beautifully.
I really appreciate your help with this.
Sorry I wasn't able to implement this code for CorelDraw X6, my coding knowledge is limited. I appreciate your response anyway. Thanks again.
No problem, over time you will see how simple it is to convert code from one language to another, especially in the context of automation.