SmartArt Through C#

T

Tat

Hey All,
I'm trying to add some smart art to a powerpoint slide using c#. How would I
go about doing this?

Currently I'm trying to add it by:
PowerPoint.Shape t1 =
slide.Shapes.AddDiagram(Microsoft.Office.Core.MsoDiagramType.msoDiagramOrgChart, 100, 100, 100, 100);

While it is compiling alright, it does not do anything.

So,
1. Is this how I would go about adding smartart?
2. Am i adding smartart or something else?
3. How do i get it to show me some kind of organisation chart?

thnaks
tat
 
T

Tat

vs2008 isn't letting me do that for some reason. Apparently I cannot overload
the argument. This is what I tried to do:

public void TrialButtonClk(Office.IRibbonControl control)
{
//to get the slideID
int slideId =
Globals.ThisAddIn.Application.ActiveWindow.Selection.SlideRange.SlideID;
//get the slide using the slideID and then query for its index
int slideindex =
Globals.ThisAddIn.Application.ActivePresentation.Slides.FindBySlideID(slideId).SlideIndex;
//to set the powerpoint presentation to a certain slide use the
slideindex obtained by the slideID

Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(slideindex);

//set up the presentation
PowerPoint.Presentation presentation =
Globals.ThisAddIn.Application.ActivePresentation;
//set up slide
PowerPoint.Slide slide =
Globals.ThisAddIn.Application.ActivePresentation.Slides[slideindex];

PowerPoint.Shape text =
slide.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 10, 10, 100, 25);
text.TextFrame.TextRange.Text = "Hello";

//PowerPoint.Shape t1 =
slide.Shapes.AddDiagram(Microsoft.Office.Core.MsoDiagramType.msoDiagramOrgChart, 50,50,50,50);
//t1.AutoShapeType =
Microsoft.Office.Core.MsoAutoShapeType.msoShapeChord;

//t1.DiagramNode.AddNode(Microsoft.Office.Core.MsoRelativeNodePosition.msoAfterNode, Microsoft.Office.Core.MsoDiagramNodeType.msoDiagramAssistant);

//PowerPoint.Shape t2 = slide.Shapes.

//t1.Diagram.AutoFormat =
Microsoft.Office.Core.MsoTriState.msoTrue;
//t1.Diagram.AutoLayout =
Microsoft.Office.Core.MsoTriState.msoTrue;
//t1.Fill.BackColor.ObjectThemeColor =
Microsoft.Office.Core.MsoThemeColorIndex.msoThemeColorAccent1;
//t1.Diagram.Type =
Microsoft.Office.Core.MsoDiagramType.msoDiagramOrgChart;
//t1.TextFrame.TextRange.Text = "hey";

//PowerPoint.Shape text =
slide.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 100, 100, 100, 25);
//t1.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 0,
0).ToArgb();
//t1.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
//t1.Diagram.AutoLayout =
Microsoft.Office.Core.MsoTriState.msoTrue;

//t1.DiagramNode.AddNode(Microsoft.Office.Core.MsoRelativeNodePosition.msoAfterLastSibling, Microsoft.Office.Core.MsoDiagramNodeType.msoDiagramNode);

//PowerPoint.Shape t1 =
slide.Shapes.AddDiagram(Microsoft.Office.Core.MsoDiagramType.msoDiagramCycle,
100, 100, 100, 100);
//slide.Shapes.AddShape(24, 100, 100, 100, 100);
PowerPoint.Shape t1 = slide.Shapes.AddShape(24, 100, 100, 100,
100);

}


cheers
tat
 
T

Tat

I'm pretty new to C# (1 week) so this isn't definitive but

'Out of curiosity (and since I'm clueless re C#), is there really no way in
C# or the other .NET langauges to do something like:

With Globals.ThisAddIn.Application
With .BlahBlah ... drilling down into the OM as you go
End With '

Should be possible but i don't really know how to do it. From the code below:

public void AddFootNotesButtonClk(Office.IRibbonControl control)
{
int slideId =
Globals.ThisAddIn.Application.ActiveWindow.Selection.SlideRange.SlideID;
int slideindex =
Globals.ThisAddIn.Application.ActivePresentation.Slides.FindBySlideID(slideId).SlideIndex;
PowerPoint.Slide slide =
Globals.ThisAddIn.Application.ActivePresentation.Slides[slideindex];

PowerPoint.Shape trial1 =
slide.Shapes.AddDiagram(Microsoft.Office.Core.MsoDiagramType.msoDiagramOrgChart, 100,100,100,100);
PowerPoint.Shape trial2 =
slide.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 200, 200, 200, 200);
trial2.TextFrame.TextRange.Text = "hello world";
trial2.TextFrame.TextRange.Font.Shadow =
Microsoft.Office.Core.MsoTriState.msoTrue;
}

This button when pressed seems to do nothing, not even say 'hello world'.
Commenting out the trial1 line (essentially loose the addDiagram) and the
hello world shows. So it's doing something, i just don't know exactly what.




Steve Rindsberg said:
vs2008 isn't letting me do that for some reason. Apparently I cannot overload
the argument. This is what I tried to do:

Try msoSmartArt in place of 24. He says, guessing wildly.

Out of curiosity (and since I'm clueless re C#), is there really no way in C# or the other .NET langauges to do something like:

With Globals.ThisAddIn.Application
With .BlahBlah ... drilling down into the OM as you go
End With

or is it really necessary to repeat all that Globals.BlahBlah for each line?

public void TrialButtonClk(Office.IRibbonControl control)
{
//to get the slideID
int slideId =
Globals.ThisAddIn.Application.ActiveWindow.Selection.SlideRange.SlideID;
//get the slide using the slideID and then query for its index
int slideindex =
Globals.ThisAddIn.Application.ActivePresentation.Slides.FindBySlideID(slideId).SlideIndex;
//to set the powerpoint presentation to a certain slide use the
slideindex obtained by the slideID

Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(slideindex);

//set up the presentation
PowerPoint.Presentation presentation =
Globals.ThisAddIn.Application.ActivePresentation;
//set up slide
PowerPoint.Slide slide =
Globals.ThisAddIn.Application.ActivePresentation.Slides[slideindex];

PowerPoint.Shape text =
slide.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 10, 10, 100, 25);
text.TextFrame.TextRange.Text = "Hello";

//PowerPoint.Shape t1 =
slide.Shapes.AddDiagram(Microsoft.Office.Core.MsoDiagramType.msoDiagramOrgChart, 50,50,50,50);
//t1.AutoShapeType =
Microsoft.Office.Core.MsoAutoShapeType.msoShapeChord;

//t1.DiagramNode.AddNode(Microsoft.Office.Core.MsoRelativeNodePosition.msoAfterNode, Microsoft.Office.Core.MsoDiagramNodeType.msoDiagramAssistant);

//PowerPoint.Shape t2 = slide.Shapes.

//t1.Diagram.AutoFormat =
Microsoft.Office.Core.MsoTriState.msoTrue;
//t1.Diagram.AutoLayout =
Microsoft.Office.Core.MsoTriState.msoTrue;
//t1.Fill.BackColor.ObjectThemeColor =
Microsoft.Office.Core.MsoThemeColorIndex.msoThemeColorAccent1;
//t1.Diagram.Type =
Microsoft.Office.Core.MsoDiagramType.msoDiagramOrgChart;
//t1.TextFrame.TextRange.Text = "hey";

//PowerPoint.Shape text =
slide.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 100, 100, 100, 25);
//t1.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 0,
0).ToArgb();
//t1.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
//t1.Diagram.AutoLayout =
Microsoft.Office.Core.MsoTriState.msoTrue;

//t1.DiagramNode.AddNode(Microsoft.Office.Core.MsoRelativeNodePosition.msoAfterLastSibling, Microsoft.Office.Core.MsoDiagramNodeType.msoDiagramNode);

//PowerPoint.Shape t1 =
slide.Shapes.AddDiagram(Microsoft.Office.Core.MsoDiagramType.msoDiagramCycle,
100, 100, 100, 100);
//slide.Shapes.AddShape(24, 100, 100, 100, 100);
PowerPoint.Shape t1 = slide.Shapes.AddShape(24, 100, 100, 100,
100);

}

cheers
tat

Steve Rindsberg said:
As usual for these new features, PPT Help doesn't.

Try .AddShape(24, etc,etc,etc) instead.

24 is the constant for IGXGraphics/SmartArt



Hey All,
I'm trying to add some smart art to a powerpoint slide using c#. How would I
go about doing this?

Currently I'm trying to add it by:
PowerPoint.Shape t1 =
slide.Shapes.AddDiagram(Microsoft.Office.Core.MsoDiagramType.msoDiagramOrgChart, 100, 100, 100,
100);

While it is compiling alright, it does not do anything.

So,
1. Is this how I would go about adding smartart?
2. Am i adding smartart or something else?
3. How do i get it to show me some kind of organisation chart?

thnaks
tat


-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
 

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