Accessing Shapes on a Cloned Slide

Hi,

I'm trying to create a presentation that has a series of slides all of the same style with certain elements being loaded from a database. When I create a slide with the layout I need and clone the slide I am unable to access any of the shapes on the cloned slide. When I check the Shapes object of the cloned slide the count is 0. On the source slide the count is 14.

Is this the correct method of approaching this task? I have tried the same with using a master slide, adding a blank slide and setting masterslide id the slide layout values. The result is the same, I end up with a Shapes count = 0.

Ged

Probably you are doing something wrong because I can’t reproduce it.
Could you provide any real example of presentation and code?

An extract of The Code to generate the Master or Template slide is:

public static Aspose.Slides.Slide MasterSlide(Presentation pres)
{
Slide slide = pres.Masters[0];
BPASlideObjectsRG.AchievementImageID = 8;
BPASlideObjectsRG.CountryImageID = 3;
BPASlideObjectsRG.PersonImageID = 5;
BPASlideObjectsRG.RetailerLogoID = 6;
try
{
slide.FollowMasterBackground = false;
slide.Background.FillFormat.ForeColor = Color.Gray;
int slideWidth = slide.Background.Width;
int slideHeight = slide.Background.Height;
BPARectangle rect = new BPARectangle();
Picture pic = new Picture(pres, WebConfigurationManager.AppSettings.Get("RSMLogoPath").ToString() + "RSMLogo.jpg");
int picId = pres.Pictures.Add(pic);
int pictureHeight = pres.Pictures[picId - 1].Image.Height * 2;
int pictureWidth = pres.Pictures[picId - 1].Image.Width * 2;
int pictureFrameWidth = 100;
int pictureFrameHeight = 100;

//Adding picture frame to the slide
PictureFrame rsmlogoFrame = slide.Shapes.AddPictureFrame(picId, pictureFrameWidth, pictureFrameHeight, pictureWidth, pictureHeight);

// Adding the heading line to the slide
Point pointStart = new Point(pictureFrameWidth, pictureFrameHeight + pictureHeight + 100);
Point pointEnd = new Point(slideWidth - 100, pictureFrameHeight + pictureHeight + 100);
Line headingLine = slide.Shapes.AddLine(pointStart, pointEnd);
headingLine.LineFormat.ForeColor = Color.Red;

// Add the Heading Info Layout
short fontHeight = 10;
pic = new Picture(pres, WebConfigurationManager.AppSettings.Get("RSMLogoPath").ToString() + "No Image.JPG");
picId = pres.Pictures.Add(pic);
PictureFrame pictureFrame = slide.Shapes.AddPictureFrame(picId, 2120, 720, 300, 300);
BPASlideObjectsRG.CountryImageFrameID = pictureFrame.ZOrderPosition;
BPASlideObjectsRG.CountryImageID = picId;
}

catch (Exception ex)
{

//Do Something
throw;
}
return slide;
}

The Code used to generate the presentation is:

public void Presentation(String AchievementIDs, String UserID, String UserDomain, String ReportType)
{

// Need to add code here to save the presentation job
BPAPresentationDetails presentationDetails = new BPAPresentationDetails(AchievementIDs, UserID, UserDomain, ReportType, "", "", DateTime.Now.ToLocalTime(), "");
presentationDetails = BPASqlBR.InsertPresentationJob(presentationDetails);

try
{
//Set some values
short fontHeight = 10;
string countryLogoPath = WebConfigurationManager.AppSettings.Get("CountryLogoPath").ToString();
string presentationPath = WebConfigurationManager.AppSettings.Get("PresentationPath").ToString();
string personImagePath = WebConfigurationManager.AppSettings.Get("PersonImagePath");
string retailerLogoPath = WebConfigurationManager.AppSettings.Get("RetailerLogoPath");

//Create the presentation
Presentation pres = new Presentation();

//Create the Master Slide
Slide masterSlide = BPAMasterSlide.MasterSlide(pres);

//Start processing the presentation Job
string[] achievementIDArray = AchievementIDs.Split(',');
int max = achievementIDArray.Length-1;
for (int achievementCount = 0; achievementCount <= max ; achievementCount++)
{
Achievement achievement = new Achievement();

//Retrieve Data from the database
achievement = BPASqlBR.GetAchievement(Convert.ToInt32(achievementIDArray[achievementCount].ToString()));
DataRow aRow = achievement.Tables[0].Rows[0];

//Clone the Master Slide
Slide slide = pres.GetSlideByPosition(pres.Slides.LastSlidePosition);
slide = pres.CloneSlide(slide, pres.Slides.LastSlidePosition + 1);
Picture pic = new Picture(pres, countryLogoPath + aRow["CountryLogoName"].ToString());
int picId = pres.Pictures.Add(pic);
PictureFrame pictureFrame = (PictureFrame) slide.Shapes[BPASlideObjectsRG.CountryImageFrameID];
pictureFrame.PictureId = picId;

// Add the Person photo
if ((aRow["PersonPhotoName"].ToString().Length != 0))
{
pic = new Picture(pres, personImagePath + aRow["PersonPhotoName"].ToString());
picId = pres.Pictures.Add(pic);
pictureFrame = slide.Shapes.AddPictureFrame(picId, rectangle.X + rectangle.Width + 100, rectangle.Y, 300, 300);
}
// Add the retailer logo
if (aRow["RetailerLogo"].ToString().Length != 0)
{
pic = new Picture(pres, retailerLogoPath + aRow["RetailerLogo"].ToString());
picId = pres.Pictures.Add(pic);
pictureFrame = slide.Shapes.AddPictureFrame(picId, slide.Background.Width - 600, 720, 400, 300);
}
}

pres.Write(presentationPath + "\\" + UserDomain + "_" + UserID + "_" + DateTime.Now.ToString("yyyyMMdd") + ".ppt");

}
catch (Exception ex)
{
throw(ex);
}

}

The code highlighted in red is where the error is being generated.

Master slides can’t be cloned. After such cloning presentation will be broken after you save it.
You should create template from normal slide and clone it as many times as you need.

Hi Sorry for the confusion. In the code supplied I should have renamed the MasterSlide object and procedures to TemplateSlide. The code creates a template slide in the proc MasterSlide at the top and then attempt to clone it. I have renamed the objects and the altered code is:

public static Aspose.Slides.Slide TemplateSlide(Presentation pres)
{
Slide slide = pres.Masters[0];
BPASlideObjectsRG.AchievementImageID = 8;
BPASlideObjectsRG.CountryImageID = 3;
BPASlideObjectsRG.PersonImageID = 5;
BPASlideObjectsRG.RetailerLogoID = 6;
try
{
slide.FollowMasterBackground = false;
slide.Background.FillFormat.ForeColor = Color.Gray;
int slideWidth = slide.Background.Width;
int slideHeight = slide.Background.Height;
BPARectangle rect = new BPARectangle();
Picture pic = new Picture(pres, WebConfigurationManager.AppSettings.Get("RSMLogoPath").ToString() + "RSMLogo.jpg");
int picId = pres.Pictures.Add(pic);
int pictureHeight = pres.Pictures[picId - 1].Image.Height * 2;
int pictureWidth = pres.Pictures[picId - 1].Image.Width * 2;
int pictureFrameWidth = 100;
int pictureFrameHeight = 100;

//Adding picture frame to the slide
PictureFrame rsmlogoFrame = slide.Shapes.AddPictureFrame(picId, pictureFrameWidth, pictureFrameHeight, pictureWidth, pictureHeight);

// Adding the heading line to the slide
Point pointStart = new Point(pictureFrameWidth, pictureFrameHeight + pictureHeight + 100);
Point pointEnd = new Point(slideWidth - 100, pictureFrameHeight + pictureHeight + 100);
Line headingLine = slide.Shapes.AddLine(pointStart, pointEnd);
headingLine.LineFormat.ForeColor = Color.Red;

// Add the Heading Info Layout
short fontHeight = 10;
pic = new Picture(pres, WebConfigurationManager.AppSettings.Get("RSMLogoPath").ToString() + "No Image.JPG");
picId = pres.Pictures.Add(pic);
PictureFrame pictureFrame = slide.Shapes.AddPictureFrame(picId, 2120, 720, 300, 300);
BPASlideObjectsRG.CountryImageFrameID = pictureFrame.ZOrderPosition;
BPASlideObjectsRG.CountryImageID = picId;
}

catch (Exception ex)
{

//Do Something
throw;
}
return slide;
}

The Code used to generate the presentation is:

public void Presentation(String AchievementIDs, String UserID, String UserDomain, String ReportType)
{

try
{
//Set some values
short fontHeight = 10;
string countryLogoPath = WebConfigurationManager.AppSettings.Get("CountryLogoPath").ToString();
string presentationPath = WebConfigurationManager.AppSettings.Get("PresentationPath").ToString();
string personImagePath = WebConfigurationManager.AppSettings.Get("PersonImagePath");
string retailerLogoPath = WebConfigurationManager.AppSettings.Get("RetailerLogoPath");

//Create the presentation
Presentation pres = new Presentation();

//Create the Template Slide
Slide templateSlide = TemplateSlide(pres);
int templatePos = pres.Slides.LastSlidePosition;

//Start processing the presentation Job
string[] achievementIDArray = AchievementIDs.Split(',');
int max = achievementIDArray.Length-1;
for (int achievementCount = 0; achievementCount <= max ; achievementCount++)
{
Achievement achievement = new Achievement();

//Retrieve Data from the database
achievement = BPASqlBR.GetAchievement(Convert.ToInt32(achievementIDArray[achievementCount].ToString()));
DataRow aRow = achievement.Tables[0].Rows[0];

//Clone the Template Slide
Slide slide = pres.GetSlideByPosition(templatePos);
slide = pres.CloneSlide(slide, pres.Slides.LastSlidePosition + 1);
Picture pic = new Picture(pres, countryLogoPath + aRow["CountryLogoName"].ToString());
int picId = pres.Pictures.Add(pic);
PictureFrame pictureFrame = (PictureFrame) slide.Shapes[BPASlideObjectsRG.CountryImageFrameID];
pictureFrame.PictureId = picId;

// Add the Person photo
if ((aRow["PersonPhotoName"].ToString().Length != 0))
{
pic = new Picture(pres, personImagePath + aRow["PersonPhotoName"].ToString());
picId = pres.Pictures.Add(pic);
pictureFrame = slide.Shapes.AddPictureFrame(picId, rectangle.X + rectangle.Width + 100, rectangle.Y, 300, 300);
}
// Add the retailer logo
if (aRow["RetailerLogo"].ToString().Length != 0)
{
pic = new Picture(pres, retailerLogoPath + aRow["RetailerLogo"].ToString());
picId = pres.Pictures.Add(pic);
pictureFrame = slide.Shapes.AddPictureFrame(picId, slide.Background.Width - 600, 720, 400, 300);
}
}

pres.Write(presentationPath + "\\" + UserDomain + "_" + UserID + "_" + DateTime.Now.ToString("yyyyMMdd") + ".ppt");

}
catch (Exception ex)
{
throw(ex);
}

}

The first line of TemplateSlide function is:
Slide slide = pres.Masters[0];
So you add PictureFrame to this master slide.

After that you clone last slide (not master) of the presentation and
try to read PictureFrame (added to master slide) from this new slide.
Why you do it? PictureFrame exists on master slide only. Cloned slide doesn’t have it!

Thank you Alexey I had missed that line. Embarrassed [:$]

Regards

Gerard