Skip to content

Instantly share code, notes, and snippets.

@zealbell
Last active July 26, 2018 15:35
Show Gist options
  • Save zealbell/8764e61c008d357d2cabfea77905746c to your computer and use it in GitHub Desktop.
Save zealbell/8764e61c008d357d2cabfea77905746c to your computer and use it in GitHub Desktop.
Macro to get coordinates of all currently selected objects in corel draw.

Here's a macro to get coordinates of all currently selected objects in corel draw.

Sub MultiGetOriginXY()
    Dim Ox As Double
    Dim Oy As Double
    Dim OxOy As String
    Dim savePath As String
    Dim fileName As String
    Dim sr As ShapeRange
    Dim s As Shape
    
    savePath = InputBox$("Enter save-location here", "Copy from folder-explorer Dialogue")
    fileName = InputBox$("Enter fileName", "FileName plus Extension")
    OxOy = ""
    Set sr = ActiveSelectionRange
    
    If sr.Shapes.Count = 0 Then
        MsgBox "You need to select a shape first"
        Exit Sub
    End If
    
    For Each s In sr.Shapes
      s.GetPosition Ox, Oy
      'convert-to px
      Ox = ConvertUnits(Ox, cdrInch, cdrPixel)
      Oy = ConvertUnits(Oy, cdrInch, cdrPixel)
      'round-off 2dp
      Ox = Round(Ox, 2)
      Oy = Round(Oy, 2)
      OxOy = OxOy & Ox & "," & Oy & "|"
    Next s
    
    MsgBox OxOy
    
    'save as text file
    Dim FsO As Object
    Set FsO = CreateObject("Scripting.FileSystemObject")
    Dim textFile As Object
    Set textFile = FsO.CreateTextFile(savePath & "\" & fileName, True, True)
    textFile.Write OxOy
    textFile.Close
    
    If FsO.FileExists(savePath) Then
        MsgBox "Done"
    End If
    
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment