none
How to create a semi circle shape using autoshape pie in VSTO for PowerPoint Addin RRS feed

  • Question

  • Hi,

    I am going mad with creating a semi circle on click of some button in the customised ribbon.

    I found a shape called "Pie" in the autoshape list.

    Microsoft.Office.Interop.PowerPoint.Shape shpPie =

    currentSlide.Shapes.AddShape(MsoAutoShapeType.msoShapePie,50f,50f,100f,100f);

    I need to create a semi circle shape out of this. Can someone pelase get me out of this.

    Wednesday, August 6, 2014 9:56 AM

Answers

  • Hi,

    In fact, there is no semi-circle shape provided in Office applications. We can only get it by editing the pie shape. You could set the ShapeRange.Adjustments Property to adjust the specified shape.

    I write a sample to get 4 different semi-circle shapes with the code below for your reference.

    private void AddSemiCircleShape()
    {
        PowerPoint.Application app = Globals.ThisAddIn.Application;
    
        PowerPoint.Slide currentSlide = app.ActivePresentation.Slides[1];
    
        Microsoft.Office.Interop.PowerPoint.Shape shpPie1 = currentSlide.Shapes.AddShape(MsoAutoShapeType.msoShapePie, 50f, 50f, 100f, 100f);
        Microsoft.Office.Interop.PowerPoint.Shape shpPie2 = currentSlide.Shapes.AddShape(MsoAutoShapeType.msoShapePie, 200f, 50f, 100f, 100f);
        Microsoft.Office.Interop.PowerPoint.Shape shpPie3 = currentSlide.Shapes.AddShape(MsoAutoShapeType.msoShapePie, 350f, 50f, 100f, 100f);
        Microsoft.Office.Interop.PowerPoint.Shape shpPie4 = currentSlide.Shapes.AddShape(MsoAutoShapeType.msoShapePie, 500f, 50f, 100f, 100f);
    
        shpPie1.Select();
        app.ActiveWindow.Selection.ShapeRange.Adjustments[1] = 90;
    
        shpPie2.Select();
        app.ActiveWindow.Selection.ShapeRange.Adjustments[2] = 180;
    
        shpPie3.Select();
        app.ActiveWindow.Selection.ShapeRange.Adjustments[2] = 90;
        app.ActiveWindow.Selection.ShapeRange.Adjustments[1] = -90;
    
        shpPie4.Select();
        app.ActiveWindow.Selection.ShapeRange.Adjustments[2] = 0;
        app.ActiveWindow.Selection.ShapeRange.Adjustments[1] = 180;
    
    }

    If you want to get other specified shape by adjusting, an easier way is to do the same steps in Excel application as you want and record a macro. Then you could refer to the recorded VBA code to write your C#/VB.NET code in VSTO add-in.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, August 7, 2014 8:26 AM
    Moderator

All replies

  • Hello Himabindu,

    It looks like your question is not related to VSTO at all. I'd recommend asking PowerPoint specific questions in the General Office Development  forum instead. You may find the Aligning Shapes in a Circle using VBA forum thread helpful.

    Also you may find the Getting Started with VBA in PowerPoint 2010 article helpful.

    Wednesday, August 6, 2014 5:06 PM
  • Hi,

    In fact, there is no semi-circle shape provided in Office applications. We can only get it by editing the pie shape. You could set the ShapeRange.Adjustments Property to adjust the specified shape.

    I write a sample to get 4 different semi-circle shapes with the code below for your reference.

    private void AddSemiCircleShape()
    {
        PowerPoint.Application app = Globals.ThisAddIn.Application;
    
        PowerPoint.Slide currentSlide = app.ActivePresentation.Slides[1];
    
        Microsoft.Office.Interop.PowerPoint.Shape shpPie1 = currentSlide.Shapes.AddShape(MsoAutoShapeType.msoShapePie, 50f, 50f, 100f, 100f);
        Microsoft.Office.Interop.PowerPoint.Shape shpPie2 = currentSlide.Shapes.AddShape(MsoAutoShapeType.msoShapePie, 200f, 50f, 100f, 100f);
        Microsoft.Office.Interop.PowerPoint.Shape shpPie3 = currentSlide.Shapes.AddShape(MsoAutoShapeType.msoShapePie, 350f, 50f, 100f, 100f);
        Microsoft.Office.Interop.PowerPoint.Shape shpPie4 = currentSlide.Shapes.AddShape(MsoAutoShapeType.msoShapePie, 500f, 50f, 100f, 100f);
    
        shpPie1.Select();
        app.ActiveWindow.Selection.ShapeRange.Adjustments[1] = 90;
    
        shpPie2.Select();
        app.ActiveWindow.Selection.ShapeRange.Adjustments[2] = 180;
    
        shpPie3.Select();
        app.ActiveWindow.Selection.ShapeRange.Adjustments[2] = 90;
        app.ActiveWindow.Selection.ShapeRange.Adjustments[1] = -90;
    
        shpPie4.Select();
        app.ActiveWindow.Selection.ShapeRange.Adjustments[2] = 0;
        app.ActiveWindow.Selection.ShapeRange.Adjustments[1] = 180;
    
    }

    If you want to get other specified shape by adjusting, an easier way is to do the same steps in Excel application as you want and record a macro. Then you could refer to the recorded VBA code to write your C#/VB.NET code in VSTO add-in.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, August 7, 2014 8:26 AM
    Moderator