We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

unable to move objects - powerpoint presentation

i have a powerpoint file with a textbox (or any other component) and i would like to move it to the other side of the slide. i wrote a simple function but it's not yielding the expected results.

i attached a zip file an image to explain the formula i came up with to do this as shown in my code, and the test file

please advise


private void MoveObject(IShape ishp, double width)

{

            if (ishp.SlideItemType is SlideItemType.Chart) ; //do something

            else if (ishp.SlideItemType is SlideItemType.Table) ; //do something


            else if (ishp.SlideItemType is SlideItemType.Picture)

                ishp.Left = width - (ishp.Left + ishp.Width);


            else if (ishp.SlideItemType is SlideItemType.GroupShape)

            {

                IGroupShape groupShape = ishp as IGroupShape;

                foreach (IShape childShape in groupShape.Shapes)

                     MoveObject(childShape, width);

            }


            else if (ishp.SlideItemType is SlideItemType.AutoShape)

                ishp.Left = width - (ishp.Left + ishp.Width);

}


Attachment: image__test_file_5819d3b1.zip

6 Replies

SB Suriya Balamurugan Syncfusion Team October 21, 2022 01:17 PM

Hi omar,

Yes. It is feasible to move the shapes to the other side of the slide as per your requirement using Syncfusion Presentation library.

On further analysis the given PowerPoint Presentation, most of the shapes are multiple nested group shapes. Your code logic to move shapes to the left is not suitable for the child shapes inside the group shape in the given PowerPoint. Because the left value of the child shapes is calculated based on the group shape bounds.

So, to resolve this problem, we suggest you to ungroup all the group shapes in your input PowerPoint document in the Microsoft PowerPoint application and then move shapes to left as per your logic using the Syncfusion Presentation library.

Also, we have found some textbox shapes having different right and left margin values. So need to shift the margin values for that shape while move to the left like a mirror.

We have prepared the sample application to
move the shapes using the modified input PowerPoint (Ungroup) and it can be downloaded from the below attachment.

Regards,
Suriya Balamurugan.


Attachment: PPTXExample_e7441c92.zip


OM omar October 22, 2022 12:58 AM

hello!


On further analysis the given PowerPoint Presentation, most of the shapes are multiple nested group shapes. Your code logic to move shapes to the left is not suitable for the child shapes inside the group shape in the given PowerPoint. Because the left value of the child shapes is calculated based on the group shape bounds.


This explains the wierd/wrong result when I ran your code against a new sample file of 3 slides. How do I ungroup? Didn't find any related method in the GroupShape class. Maybe under a different name? Attached zip file has test 1 and test 1 result pptx files


Also, we have found some textbox shapes having different right and left margin values. So need to shift the margin values for that shape while move to the left like a mirror.

I ran your code against a new sample of 4 slides. System.ArgumentException: 'Invalid Margin Left' was caused at the line ishp.TextBody.MarginLeft = ishp.TextBody.MarginRight; ​for each of those slides. ​​Attached zip file has test 2 pptx file. Btw, running the above sample (test 1.pptx) against this code didn't produce this exception.


Attachment: test_1_2_acac5da.zip



OM omar October 23, 2022 12:14 PM

This is the right code to traverse through nested groupshapes. With this part, I am now confident that i can go through all the shapes in the slides

private void MoveObject(int slideNumber, ISlideItem isl)

{

if (isl.SlideItemType == SlideItemType.GroupShape)

{

IGroupShape igs = isl as IGroupShape;

for (int i = 0; i < igs.Shapes.Count; i++)

MoveObject(slideNumber, igs.Shapes[i]);

}

}


  1. how do you ungroup programatically? if there is no such method in your library, this means i'll have to create a copy of the powerpoint file, move everything IN the groupshapes to it and keep track of that, and then in that new file, i'll do the mirror movement part and then i'll group the shapes again. or is there another workaround for this?
  2. i still don't understand the left margin exception as mentioned in the previous post
  3. it is not my intention to double post but i didn't knwo if it's okay to write my progress in a separate post or if i should have just edited the previous post. sorry. please advise for next time


SB Suriya Balamurugan Syncfusion Team October 24, 2022 10:47 AM

Hi omar,

Currently we are trying to reproduce the reported problem and we will share the further details on 26th October 2022.

Regards,
Suriya Balamurugan.



SB Suriya Balamurugan Syncfusion Team October 26, 2022 09:56 AM

Hi omar,

Please find the details below,

Queries

Details

This explains the wierd/wrong result when I ran your code against a new sample file of 3 slides. How do I ungroup? Didn't find any related method in the GroupShape class. Maybe under a different name? Attached zip file has test 1 and test 1 result pptx files

Currently Essential Presentation does not provide “API to Ungroup shapes in the PowerPoint Presentation”. We don’t have any immediate plans to implement this feature.

As mentioned earlier to achieve your requirement, we suggest you to ungroup all the group shapes in your input PowerPoint document in the Microsoft PowerPoint application.

In your attached zip file has test 1 which contains group shapes. So, running this sample cause improper/wrong result. We suggest you to ungroup all the group shapes in the Microsoft PowerPoint application and then use that modified input document into this sample to get the expected result.

Attached the modified input document (Ungroup in Microsoft PowerPoint application) in below attachment.

I ran your code against a new sample of 4 slides. System.ArgumentException: 'Invalid Margin Left' was caused at the line ishp.TextBody.MarginLeft = ishp.TextBody.MarginRight; ​for each of those slides. Attached zip file has test 2 pptx file. Btw, running the above sample (test 1.pptx) against this code didn't produce this exception.

This exception is due to the sample level code changes in our provided sample in our previous post. We have modified the sample application to resolve the exception and it can be downloaded from the below attachment.

how do you ungroup programatically? if there is no such method in your library, this means i'll have to create a copy of the powerpoint file, move everything IN the groupshapes to it and keep track of that, and then in that new file, i'll do the mirror movement part and then i'll group the shapes again. or is there another workaround for this?

To achieve your requirement, if you have group shape means, you need to ungroup. But currently Essential Presentation does not provide “API to Ungroup shapes in the PowerPoint Presentation”. We don’t have any immediate plans to implement this feature.

We suggest you to ungroup all the group shapes in the Microsoft PowerPoint application and then use that modified input document into this sample to get the expected result.

No other workaround to achieve your requirement.

i still don't understand the left margin exception as mentioned in the previous post

As mentioned earlier, this exception is due to the sample level code changes in our provided sample in our previous post. We have modified the sample application to resolve the exception and it can be downloaded from the below attachment.

it is not my intention to double post but i didn't knwo if it's okay to write my progress in a separate post or if i should have just edited the previous post. sorry. please advise for next time

You can edit your previous post until we reply to your new post. Otherwise, write your progress in separate post.

If your query is related to already shared post means, please update in same thread/ticket. Otherwise create new thread/ticket.


Regards,
Suriya Balamurugan.


Attachment: Attachment_b0dfc6f4.zip


OM omar October 27, 2022 10:20 AM

thank you very much for the reply. I'm going to compare your first version to the second version to better understand the changes.

i especially am thankful for letting me know when you're going to reply. i think you should do that all the time. at least we would know when to expect a response instead of a big ? hanging in the air :D

i'll come back here later tomorrow and mark this as answered if i'm done.


Loader.
Live Chat Icon For mobile
Up arrow icon