PPT2003 Rounded Rectangle Corner Radius - Inconsistent Results

L

Lee Diggins

Hi

I have a number of different size rounded rectangles being inserted at
runtime and would like to apply the same corner radius to each of the rounded
rectangles.

I tried to calculate the rounded rectangle corner radius dynamically based
upon the height of the rectangle, but, unfortunately I cannot produce
consistent results and I can only assume that there's more than the height of
the rectangle that is taken into consideration when sizing the corner or my
calculations are rubbish.

Anyway here's the function I thought would work using base settings of
height and radius I would like applied, the function is used to set the
Adjustments(1) property on the rectangle:

Parameter h is the height of the rectangle
Variables:
bh is base height
br is base radius
p is the precentage base radius is of base height
o is the calculated rectangle radius value

Function CalculateRadius(h As Single) As Single
Dim bh As Single, br As Single, p As Single, o As Single
If h = DATE_H Then
o = RADIUS_RR
Else
bh = DATE_H
br = RADIUS_RR
p = (RADIUS_RR / DATE_H) * 100
o = (h * p) / 100
End If
CalculateRadius = o
End Function

Any pointers, nudges in the right direction, information on what the
Adjustments(1) property for rounded rectangle works (I can't find anything
specific on rectangles) would be greatly appreciated.

Regards,

Lee
 
L

Lee Diggins

Hi Steve

Yeah, a few lessons learned along the way about how the rounded corners are
handled (no pun intended). Also, I might not be exactly correct here as per
MS, but, these are my findings.

I also called this the radius of the corner, not necessarily the correct
thing to call it, but, hey I know what I’m talking about.

The radius of the corner is set by supplying a Single data type value to the
Adjustments(1) property, for example:
ActivePresentation.Slides(indexorname).Shapes(indexorname).Adjustments(1) =
0.2

Note: The corner radius is calculated using the shortest side of the
rectangle.
What I was after was the exact same radius in the corner regardless of the
size of the rectangle, here's how.

You need to have a base length and a base Adjustments(1) value, these will
represent the radius size you want to apply to other rounded rectangles. You
can do this by creating a new blank presentation, remove any text boxes etc
from the slide and draw a rounded rectangle. Adjust the corner using the
yellow adjusting handle, you can then get the radius value like this:

Sub GetBase()
Dim s As Shape, w As Single, h As Single, l As Single, a As Single
Set s = ActiveWindow.Selection.ShapeRange(1)
With s
a = .Adjustments(1)
h = .Height
w = .Width
End With
If h <> w Then
If h > w Then
l = w
Else
l = h
End If
Else
l = w
End If
MsgBox "Base Length: " & l & vbCrLf & "Base Radius: " & a
Set s = Nothing
End Sub

The radius of the corner is calculated using the base values supplied
(length and radius) and working out the ratio the radius is of the length,
this ratio is then used to calculate the return value required for the target
rectangle.

Here’s the function, very straight forward:
Parameters and variables - h = height of target rectangle, w is width of
target rectangle, bl is base length, br is base radius, r is ration and x is
the return value.

Function CalculateRadius(h As Single, w As Single, bl As Single, br As
Single) As Single
Dim r As Single, x As Single
r = bl * br
If h <> w Then
If h > w Then
x = r / w
Else
x = r / h
End If
Else
x = r / w
End If
CalculateRadius = x
End Function

Hope I’ve made sense, if not post back.

Regards,

Lee
 
L

Lee Diggins

Hi Steve

No problem at all. I've consumed your code in the past, it's my #1 favourite
for PPT dev so I'd be pleased to contribute and give something back.

Regards,

Lee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top