We are designers of sporting events on the open roads and currently use corel to design these schemes inserting pre-drawn elements on to maps etc.
I am looking for a way to automate the counting of these objects by there name to give me totals rather than using the 'Look for Object Names or Styles' function in Find Objects which I have to repeat 60+ times to find each object name.
i.e. Circle 1 = 20, Circle 2 = 23, Square 3 = 33
Ideally it would be great if these were displayed in a table or just being able to copy and paste in excel would be perfect.
Does anyone now of a solution of possible code that would do this?
To copy in clipboard, you can paste in excel, and a generic code for get all shapes
CGSaddon download
C# Code
public void CountShapeByName() { Dictionary<string, int> s = new Dictionary<string, int>(); ShapeRange shapes = app.ActiveDocument.SelectableShapes.All(); for (int i = 1; i <= shapes.Count; i++) { if (!s.ContainsKey(shapes[i ].Name)) { s.Add(shapes[i ].Name, 1); } else { s[shapes[i ].Name]++; } } string msg = ""; foreach (var item in s) { msg += item.Key + "\t"; } msg += System.Environment.NewLine; foreach (var item in s) { msg += item.Value + "\t"; } System.Windows.Forms.Clipboard.SetText(msg); System.Windows.Forms.MessageBox.Show("Copied"); }
HI
I have used this script and it works very well, however I have now set up all my Objects as Symbols because I use them all the time. The script now only gives me a total and no longer breaks its down to each individual item as per its name. I have used the same names in the Symbols but it wont count them correctly. What change would I need to make to the above script to get this to work correctly. Am using 2018
Thanks Grant
Change shapes[i ].name to shapes[i ].Symbol.Definition.Name
Thanks for that. How do I edit the CGS file. I can change the file in Excel but cant work out how to save it as a CGS file to allow import into Corel. I tried the onboard Edit function within the Macro but it does not seem to load anything
Thanks again
Visual studio