Monthly Archives: June 2012

Determining the length of a curve in Corel Draw 11

2012-06-21

When designing in Corel Draw, it can be very useful to know the total length of a curve. Since the curve may consist of straight and curved sections, this is not trivial, and unfortunately the user interface doesn’t help you here – it only tells you the width and height of an object.

So in order to get that length, use this Visual Basic macro:

Sub getLineLen()
 Dim sel As Shape
 Set sel = Application.ActiveDocument.ActiveShape
 Dim l, sl As Double
 Dim seg As Segment
 Dim prevu As cdrUnit

 prevu = Application.ActiveDocument.Unit
 Application.ActiveDocument.Unit = cdrMillimeter

 For Each seg In sel.Curve.Segments
 sl = seg.Length
 l = l + sl
 Next seg
 MsgBox ("Length: " & l)

 Application.ActiveDocument.Unit = prevu
End Sub

This should work in other versions of Corel Draw, too, but I could verify that for version 11 only. In order to make this work, go to the menu item “Tools -> Visual Basic -> Visual Basic editor…”. Click on “GlobalMacros”, then on “Module” and “CorelMacros”. Paste the code at the bottom of this text file. Then click on File -> Save.

To use the macro, select the relevant curve, then click on “Tools -> Visual Basic -> Execute…”. Select the macro from the list (select “Macros in” “all standard projects”) and click on “Execute”. The length of the curve will appear in a small message box.