Search code examples
c#powerpointoffice-interop

How do I get the direction of a callout arrow on a msoShapeRoundedRectangularCallout?


I am saving out images of shapes in a presentation and I can't figure out how to get the distance and direction of the callout arrow on a rounded corner rectangle with a callout. The MSOautoshape 106: Yellow corner is top left position, but image saved image has offset due to callout.

enter image description here

var tempString = shape.AutoShapeType.ToString();
if ( tempString.Contains("Callout")){
Debug.WriteLine(shape.Callout.Angle);
}

This code throws an error that it only works with "LINE" callouts. I'm kinda at a loss on how to solve this one. Please help.


Solution

  • The Callout property is, indeed, only valid for "line callouts":

    enter image description here

    The kind of shape shown in the question uses the Adjustments property to read/control the settings to a Shape:

    Word.Shape shp = ActiveDocument.Shapes[1];
    Word.Adjustments = adj = shp.Adjustments;
    for (int p = 1; p<=adj.Count; p++)
    {
        Debug.Print(adj.Item[p].ToString());
    }
    

    It's necessary to experiment with the specific Shape and various generated settings to determine what the various values signify. In my tests with the specified Shape I got three adjustment values. The first appeared to indicate the angle/offset of the callout, the second the length/distance to the rectangle and the third I wasn't able to determine (was static).

    From the object model language reference:

    Type of Adjustment Valid values

    Linear (horizontal or vertical)

    Generally the value 0.0 represents the left or top edge of the shape and the value 1.0 represents the right or bottom edge of the shape. Valid values correspond to valid adjustments you can make to the shape manually. For example, if you can only pull an adjustment handle half way across the shape manually, the maximum value for the corresponding adjustment will be 0.5. For shapes such as callouts, where the values 0.0 and 1.0 represent the limits of the rectangle defined by the starting and ending points of the callout line, negative numbers and numbers greater than 1.0 are valid values.

    Radial

    An adjustment value of 1.0 corresponds to the width of the shape. The maximum value is 0.5, or half way across the shape.

    Angle

    Values are expressed in degrees. If you specify a value outside the range – 180 to 180, it will be normalized to be within that range.