I'm looking for a macro that can detect distance between objects. Is there one that can do that? I want to be able to give a value and then have the script search and find any objects that are closer to each other than the value specified. Thanks
Joseph
I think this will do it then ...
Dim ss As Shapes minimum_gap = 0.05 'value in inches, change as required Set ss = ActiveLayer.Shapes For i = 1 To ss.Count 'do every shape found If ss(i).Type = cdrEllipseShape Then For j = i + 1 To ss.Count 'compare it with every shape we haven't yet done If ss(j).Type = cdrEllipseShape Then distance_x = ss(j).CenterX - ss(i).CenterX distance_y = ss(j).CenterY - ss(i).CenterY distance = Sqr((distance_x * distance_x) + (distance_y * distance_y)) End If radius_i = ss(i).CenterX - ss(i).LeftX + ss(i).Outline.Width / 2 radius_j = ss(j).CenterX - ss(j).LeftX + ss(j).Outline.Width / 2 gap = distance - radius_i - radius_j If gap < minimum_gap Then ss(j).Fill.UniformColor.CMYKAssign 0, 100, 100, 0 End If Next j End If Next i
As currently written, it assumes all circles are on the active layer, so you can have other objects in the document without them being considered. It also presumes all the objects are circles
Cool, I'll give it a try. So the concept here is to set the distance within the code and "select" the objects I want to check, correct?
jt123 said:the circle may have a stroke thickness and the bounding box doesn't consider that
That is correct. Or at least, that is what it does -- "correct" behaviour would be for the bounding box to already include the outline.
Incidentally, the in X7 the outline has additional options to be inside or outside the object, so the "half thickness" is not necessarily correct there. Anybody wanting to adapt this for X7 should consider adding some condiitonal code that would add the correct value.
There is a guide book, but it is far from complete. If you're using windows 7 or XP you will find it in the windows start menu:
If you are using windows 8, then you will probably need to go to the actual location, which is probably "C:\Program Files\Corel\CorelDRAW Graphics Suite X6\Data\Macro Programming Guide.pdf"
It contains information to get you started, but is that is as far as it goes -- and it almost misses out photopaint altogether.
There is also a help file -- which you would think would be available in the VBA editor under the help menu, but it is not. The help menu there goes to microsoft VBA help. To get to the CorelDraw VBA help you have to use a trick which is as far as I'm aware completely undocumented:
And now you get to the help file, which could and should have been in the help menu all along.
The help file does have detailed information about most (but not all) VBA keywords, but unless you already know the name of the IsOnShape function it can be difficult to guess the right words to find it by searching.
harryLondon said:but unless you already know the name of the IsOnShape function it can be difficult to guess the right words to find it by searching
Indeed, which is why I would chime in and suggest using this neat trick:
harryLondon said: find a VBA keyword that is unique to CorelDraw, such as ActiveLayer type that in the VBA editor highlight it and press F1
and just reading up on Properties and Methods of a given thing (say, Shape) - gives you a good idea of what's possible.