none
Getting error when adding a custom smartart shape in PowerPoint RRS feed

  • Question

  • I created 3 smartart shapes, and put them into the folder: "C:\Users\...\AppData\Roaming\Microsoft\Templates\SmartArt Graphics", and the PowerPoint load them successfully. You can call them from the UI, however if at the beginning once the PowerPoint is opened, and I add a smartart shape into slide programmatically, I always get the following error:

    "The index into specified collection is out of bounds"

    However If I add my smartart shape from UI first, there is no error if I want to add my smartart shape from code after that.

    My smartart shapes: SmartArts

    My code is:

    Microsoft.Office.Core.SmartArtLayout myLayout = null;

    try 

    {

           myLayout = PowerPointApp.SmartArtLayouts["SmartArtABS3"];

    }

    catch (Exception ex)

    {

            MessageBox.Show(ex.Message);

            questionLayout = null;

    }                

    if (questionLayout != null)

    {

            PowerPoint.Shape smShape = allShapes.AddSmartArt(myLayout, left, top, width, height);

    //.....

    }

    Note: I am using VS Ultimate 2013, PowerPoint 2013, C#, Add-In-Express
    Wednesday, November 19, 2014 3:16 PM

Answers

  • Hi chipbk11,

    Base on my test, I can reproduce that issue too.

    I think the reason is that the custom SmartArt data not loaded.

    Please use this code below to load the data first. (before myLayout=…)

    int count = this.Application.SmartArtLayouts.Count;

    Best Regards

    Starain


    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.

    • Marked as answer by chipbk11 Friday, November 21, 2014 10:28 AM
    Friday, November 21, 2014 9:08 AM
    Moderator

All replies

  • Hello,

    What property or method call exactly fires the exception? Did you try to debug the code?

    > "The index into specified collection is out of bounds"

    The index starts from 1 in office applications, not from zero (0) like in .Net based applications. Is this the case?

    Wednesday, November 19, 2014 8:10 PM
  • Thanks for your response. The index starts from 1, I already know. PowerPoint seems not to load my smartart layout until I click on SmartArt button from the menu.

    We get a layout from the list of all smartart layouts via its id. Id of a layout is defined as a unique string in the LayoutHeader.xml of the glox file. So my layout's Id is "SmartArtABS3".

    There are 2 cases:

    1) Open PowerPoint --> Click SmartArt from the menu --> and then from Code, get my layout successfully:

    myLayout = PowerPointApp.SmartArtLayouts["SmartArtABS3"];

    2) Open PowerPoint -> from Code, failed to get my layout:

    myLayout = PowerPointApp.SmartArtLayouts["SmartArtABS3"];

    Wednesday, November 19, 2014 8:24 PM
  • Did you try to use the index to get an instance of the SmartArtLayout class and then compare the Name property? I.e. iterate over all objects in the collection checking the Name property. Does it work?
    Thursday, November 20, 2014 3:09 PM
  • Hi chipbk11,

    Base on my test, I can reproduce that issue too.

    I think the reason is that the custom SmartArt data not loaded.

    Please use this code below to load the data first. (before myLayout=…)

    int count = this.Application.SmartArtLayouts.Count;

    Best Regards

    Starain


    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.

    • Marked as answer by chipbk11 Friday, November 21, 2014 10:28 AM
    Friday, November 21, 2014 9:08 AM
    Moderator
  • Thanks for your help. It solved!
    Friday, November 21, 2014 10:28 AM