0
votes

I try to ungroup a SmartArt shape from code, but it always causes an error: "This member can only be accessed for a group".

However, it's working, if I right click on the SmartArt shape, and ungroup it.

How can I fix this?

My code is:

public void CreateSmartArt(PowerPoint.Shapes allShapes)

{

     PowerPoint.Shape smartartShape = allShapes.AddSmartArt(IttPowerPoint.Instance.PowerPointApp.SmartArtLayouts["MyLayOut"], 0f, 0f, width, height);

     Marshal.ReleaseComObject(smartartShape); smartartShape = null;

}



Public void UngroupSmartArt(PowerPoint.Shape shape)

{

     try

     {

            shape.Ungroup();

     }

     catch (Exception ex)

     {

            MessageBox.Show(ex.Message);

     }
}

Note: I am using VS Ultimate 2013, PowerPoint2013, C#

2
You can only ungroup a shape group not the shapes that make up the group. You need to find the correct shape to pass to your function.Mr. Mascaro
Ok, so my question is how to ungroup a smartart shape programmatically? We can ungroup a smartart shape by right clicking on it and then group->ungroup. How can we make it from code?chipbk10
You'll have to find the group shape. Loop through all of the shapes until you find one of the group type.Mr. Mascaro

2 Answers

1
votes

In VBA, you'd do it like so, asssuming a reference to the smartart shape in osh:

osh.Copy
osh.Delete
Set osh = ActiveWindow.Selection.SlideRange(1).Shapes.PasteSpecial(ppPasteEnhancedMetafile)(1)
With osh.Ungroup
    .Ungroup
End With

Copy the SmartArt shape to the clipboard Delete it from the slide Paste it back onto the slide as an Enhanced Metafile Ungroup it then ungroup the result.

Voila. Shapes.

You'll want to pick up the top/left coordinates of the Smart Art before copying/deleting it, then apply them to the pasted EMF.

0
votes

Take a look at the Parent and ParentGroup properties of the Shape object. This might solve your problem.