Outline Width

I had a simple macro in Corel 2020 to toggle the outline on and off. Since I updated to 2023 I've been getting a weird bug.

If there is no outline, it's creating an outline in inches. instead of 0.5pts default. What am I missing?

Sub Toggle_Outline()
  Dim s As Shape
  For Each s In ActiveSelectionRange.Shapes
    
    If s.Outline.Width > 0 Then
      s.Outline.SetNoOutline
    ElseIf s.Outline.Width = 0 Then
      's.Outline.SetProperties 1    <-----Was working in 2020.
      s.Outline.SetProperties 0.5 'tried to change to 0.5pt but makes a outline .5" wide.
    End If
  
  Next s
End Sub
  • Found this convert units code and this fixed the issue. https://community.coreldraw.com/talk/coreldraw_graphics_suite_x6/f/coreldraw-x6/39529/units-in-vba


    Sub Toggle_Outline()
      Dim s As Shape
      Dim x As Double
      
      x = ConvertUnits(0.5, cdrPoint, cdrInch)
      
      For Each s In ActiveSelectionRange.Shapes
        
        If s.Outline.Width > 0 Then
          s.Outline.SetNoOutline
        ElseIf s.Outline.Width = 0 Then
          s.Outline.SetProperties x
        End If
      
      Next s
    End Sub
    
  • A lot of things in CorelDRAW depend on what the document units are. The document units are not necessarily the units you see in the user interface. You can get it or set it as the ActiveDocument.Unit property.

    In a lot of little macros, you will see people changing ActiveDocument.Unit to make it more convenient to work in a particular unit - but they often are not bothering to change it back to what it was, which could cause problems if one subsequently used other macros that assumed a particular unit was in use for the document.

    I prefer to not change ActiveDocument.Unit, and to instead use ActiveDocument.ToUnits to make sure that I am getting the correct values, regardless of what ActiveDocument.Unit might be.

    • Got it! I found your similar comment about ActiveDocument.ToUnits. I'll keep this in mind when I run into that next time!

      • I changed the page measurement unit to cm, used a code like appDRAW.ActiveDocument.Unit = appDRAW.Unit.cdrMillimeter, the page measurement unit did not change. I don't understand what kind of problem it causes.

        • I don't understand what kind of problem it causes.

          If I offer someone a code snippet to set the width of an outline in millimeters, I don't need to also change the value of ActiveDocument.Unit - which could affect the way that other macros work (if those macros were written with the assumption that ActiveDocument.Unit was inches).