In an attempt to automate a somewhat tedious manual procedure, I'd like to create a macro to add small triangle shapes around a variable number of boxes. Before i invest any time into this venture can anyone tell me if it is even possible? FWIW, we're still using CorelDRAW 2017 and have no immediate plans to upgrade.
The number and size of boxes will vary. I want to end up with a small triangle around the perimeter to indicate the through-cut location of each individual box.
Here is an example of what the end result should look like:
And here are the specifications for desired triangle shape and location:
I think that's certainly possible, but the complexity might depend on the variety of content with which you want to work.
1 - The rectangle carrier shapes and quantities will usually change per job, so almost every job ends up being a custom layout.
2- Whenever possible parts are set up to have common edges to speed up cut time. We used to allow a .125" spacing between parts in order to have a visual guide for cutting apart after weeding and premasking. If we pack the parts in with common cut edges we can cut and weed faster but then there is no indication where to cut into individual parts. Currently we are manually placing the small triangles as cut indicators.
An idea comes to my mind, but it wouldn't be a "brilliant", fully-automated solution that would examine all of the content, and then figure out where the cut indicators should go.
It would be something only semi-automated, where the user could select multiple shapes, then have the macro place indicators of a particular type, for example:
In all cases above, "located at" would also include the specified offset distance from the reference shape corner.
That would not be a one-click solution, but it could significantly reduce the tedium, and it would work with many different types of layouts.
We could deal with having to run four different macros. It'd still be faster than placing each triangle separately. I'll see what I can come up with. My VB skills are a bit meager but I'll give it a go.
Thank you!
What I was thinking of would involve eight different ways of placing cut indicators. That could be done as independent macro subs, but I think it would be easier for the user to have a user form with eight buttons (arranged around a square to make it easier to understand which type of indicator placement each button performs)
I think that I would build most of the heavy lifting into a single "create cut indicator" function. That way, each of the eight variations would be fairly simple.
We can discuss more if you like. This one is "bite sized" enough that it might be fun to write.
This is the sort of thing I was thinking of when I suggested having a "create cut indicator" function:
Function create_cut_marker(ByVal Layer As Layer, ByVal PositionX As Double, ByVal PositionY As Double, ByVal Angle As Double, ByVal Width As Double, ByVal Length As Double) As Shape Dim curveThis As Curve Dim subPathThis As SubPath Dim transmatrix As New TransformMatrix On Error GoTo ErrHandler Set curveThis = CreateCurve(ActiveDocument) Set subPathThis = curveThis.CreateSubPath(PositionX, PositionY) subPathThis.AppendLineSegment PositionX - Length, PositionY - Width / 2 subPathThis.AppendLineSegment PositionX - Length, PositionY + Width / 2 subPathThis.Closed = True transmatrix.BindToDocument ActiveDocument transmatrix.RotateAround Angle, PositionX, PositionY curveThis.ApplyTransformMatrix transmatrix Set create_cut_marker = ActiveLayer.CreateCurve(curveThis) create_cut_marker.Fill.ApplyUniformFill Application.CreateCMYKColor(0, 0, 0, 100) create_cut_marker.Outline.SetNoOutline ExitFunc: Exit Function ErrHandler: MsgBox "Error occurred: " & Err.Description & vbCrLf & vbCrLf & "create_cut_marker()" Resume ExitFunc End Function
That can then be used in any particular type of placement operation. Here's a sub to create right-pointing cut markers at the top left corner of each selected shape. The marker width, marker length, and offset distance are constants defined elsewhere in the module.
Sub cut_markers_top_left_pointright() Dim sRef As Shape Dim srSelected As ShapeRange On Error GoTo ErrHandler Optimization = True EventsEnabled = False ActiveDocument.BeginCommandGroup "cut markers TL PR" Set srSelected = ActiveSelectionRange For Each sRef In srSelected create_cut_marker ActiveLayer, sRef.LeftX - dblOffset, sRef.TopY, 0, dblMarkerWidth, dblMarkerLength Next sRef srSelected.CreateSelection ExitSub: ActiveDocument.EndCommandGroup EventsEnabled = True Optimization = False Refresh Exit Sub ErrHandler: MsgBox "Error occurred: " & Err.Description Resume ExitSub End Sub
A lot of stuff in there is essentially boilerplate - error handling, optimization, and to allow all of the operations to be in a command group to allow for a one-click Undo. The actual creation of the markers is one line of code in a for...next loop.
Even without creating a user form, it's possible to put a number of independent subs in a toolbar as commands with descriptive captions using regular CorelDRAW workspace customization.
Here's a demo:
Wow! That looks fabulous! I'll give it a go and see how it work.
I can't seem to figure out how to post code without is being part of the message text. Probably for the best. As I mentioned my macro coding skills are meager at best. I know enough to make a huge mess of things. My efforts so far have resulted in arrows at the corners and not much else.
At any rate, thank you very much! You've inspired me to improve my coding skills.
For posting code, you can use the hilite.me web site to convert your VBA code into formatted HTML. Copy that, and you can paste it into your forum post here after using Tools>Source Code in the editor to edit the post in HTML.
Here's a .ZIP archive with the .GMS file that includes the whole ball of wax that I showed in that demo video:
Cut_Markers.zip
.