Here's a CorelDRAW X8 VBA script that finds an object with a CMYK(0,100,100,0) outline and identifies the bottom-most object in the active layer:
Sub FindSpecificOutlineAndBottomObject()
Dim doc As Document
Dim page As Page
Dim shape As Shape
Dim foundOutlineObject As Shape
Dim bottomObject As Shape
Dim targetColor As Color
' Check if there's an active document
If Documents.Count = 0 Then
MsgBox "No document is open.", vbExclamation
Exit Sub
End If
Set doc = ActiveDocument
Set page = doc.ActivePage
' Create the target color (CMYK 0,100,100,0 - which is red)
Set targetColor = CreateCMYKColor(0, 100, 100, 0)
' Initialize variables
Set foundOutlineObject = Nothing
Set bottomObject = Nothing
' Loop through all shapes on the active page
For Each shape In page.Shapes
' Check if shape has an outline
If shape.Outline.Type <> cdrNoOutline Then
' Check if the outline color matches our target
If shape.Outline.Color.IsSame(targetColor) Then
Set foundOutlineObject = shape
End If
End If
' The first shape in the collection is the bottom-most
If bottomObject Is Nothing Then
Set bottomObject = shape
End If
Next shape
' Report results
Dim message As String
message = ""
If Not foundOutlineObject Is Nothing Then
message = "Found object with CMYK(0,100,100,0) outline: " & vbCrLf
message = message & "- Name: " & foundOutlineObject.Name & vbCrLf
message = message & "- Type: " & GetShapeTypeName(foundOutlineObject) & vbCrLf & vbCrLf
' Optionally select the object
foundOutlineObject.CreateSelection
Else
message = "No object found with CMYK(0,100,100,0) outline." & vbCrLf & vbCrLf
End If
If Not bottomObject Is Nothing Then
message = message & "Bottom-most object in layer: " & vbCrLf
message = message & "- Name: " & bottomObject.Name & vbCrLf
message = message & "- Type: " & GetShapeTypeName(bottomObject)
' If you want to select both objects (if both found)
If Not foundOutlineObject Is Nothing Then
bottomObject.AddToSelection
Else
bottomObject.CreateSelection
End If
End If
MsgBox message, vbInformation, "Search Results"
End Sub
' Helper function to get shape type name
Function GetShapeTypeName(shape As Shape) As String
Select Case shape.Type
Case cdrRectangleShape: GetShapeTypeName = "Rectangle"
Case cdrEllipseShape: GetShapeTypeName = "Ellipse"
Case cdrCurveShape: GetShapeTypeName = "Curve"
Case cdrTextShape: GetShapeTypeName = "Text"
Case cdrBitmapShape: GetShapeTypeName = "Bitmap"
Case cdrGroupShape: GetShapeTypeName = "Group"
Case Else: GetShapeTypeName = "Other"
End Select
End Function
To use this script:
- Open CorelDRAW X8
- Press Alt+F11 to open the VBA editor
- Insert a new module (Insert → Module)
- Copy and paste the code above
- Run the macro by pressing F5 or going to Tools → Macros → Run
The script will:
- Search through all objects on the active page
- Find any object with a CMYK(0,100,100,0) outline (which is red)
- Identify the bottom-most object in the layer stack
- Display information about both objects in a message box
- Select the found objects
Note that in CorelDRAW's object hierarchy, the first shape in the Shapes collection is the bottom-most (back-most) object, and the last one is the top-most.
If you need to search within specific layers or handle grouped objects differently, let me know and I can modify the script accordingly.