Free Support Forum - aspose.com

Connector is not connected to a shape inside the group


#1

Hi, I have next issue:

I’m trying to group added shapes on the slide and then create a connector to one of the shapes from the group.
When I save PPTX and open it - anchor at the group level is not connected.

Noticed next: if I reopen stored presentation and connect again to the same shape and re-save again - it will create a corrector anchor.

Check the code below:

var fileNameToSave = $"Result_{DateTime.Now.Hour:00}_{DateTime.Now.Minute:00}_{DateTime.Now.Second:00}.pptx";
        var fileNameToSave1 = $"Result_{DateTime.Now.Hour:00}_{DateTime.Now.Minute:00}_{DateTime.Now.Second:00}_1.pptx";

        using (var presentation = new Presentation())
        {
            var slide = presentation.Slides[0];

            var rootShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 300, 100, 140, 30);
            rootShape.TextFrame.Text = "root item text";

            var itemForGrouping1 = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 300, 300, 140, 30);
            itemForGrouping1.TextFrame.Text = "grouping item 1";

            var itemForGrouping2 = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 300, 350, 140, 30);
            itemForGrouping2.TextFrame.Text = "grouping item 2";

            var group = slide.Shapes.AddGroupShape();
            var targetShape = (IAutoShape)group.Shapes.AddClone(itemForGrouping1);
            targetShape.Name = "test shape";

            group.Shapes.AddClone(itemForGrouping2);

            // remove ungrouped original shapes
            slide.Shapes.Remove(itemForGrouping1);
            slide.Shapes.Remove(itemForGrouping2);

            var arrow = slide.Shapes.AddConnector(ShapeType.CurvedConnector2, 0, 0, 10, 10);
            arrow.StartShapeConnectionSiteIndex = 2;
            arrow.StartShapeConnectedTo = rootShape;
            arrow.EndShapeConnectedTo = targetShape;   // while debugging - I see that this property contains correct Target Shape. Is not null
            arrow.EndShapeConnectionSiteIndex = 0;
            arrow.Name = "connector 1";

            presentation.Save(fileNameToSave, Aspose.Slides.Export.SaveFormat.Pptx);

            var storedPresentation = new Presentation(fileNameToSave);

            var connector = storedPresentation.Slides[0].Shapes.First(x => x.Name == "connector 1") as IConnector;

            if (connector.EndShapeConnectedTo == null)
            {
                Console.WriteLine("Anchor is lost");
            }

            connector.EndShapeConnectedTo = (storedPresentation.Slides[0].Shapes.First(x => x is IGroupShape) as IGroupShape).Shapes.First(x => x.Name == "test shape");

            storedPresentation.Save(fileNameToSave1, Aspose.Slides.Export.SaveFormat.Pptx);  // now connector is attached to the anchor correctly in presentation and on reloading endshape is not NULL anymore.
        }

#2

@LostAndFound,

I have worked with source file shared by you. Can you please share expected result and generated result so that we may further investigate to help you out.


#3

Sure, here it is.

I did also 2 screenshots explaining what is happening during first save and second save process.
On first Save I need to achieve same result as I got after only second Save. See the attachment
example.zip (76.4 KB)

In the code above the issue is here. It should not happen:
if (connector.EndShapeConnectedTo == null)
        {
            Console.WriteLine("Anchor is lost"); // Should not happen, but is happening for some reason. How to avoid it?
        }

#4

@LostAndFound,

I have worked with sample code shared by you and have been unable to observe issue. I have also shared my generated result with you for your kind reference. Please check attachment. I dont have to open presentation again and save it again to achieve results. Can you please share which Aspose.Slides version you are using on your end, if you are using old version please try to use Aspose.Slides latest version 19.2 on your end and share feedback with us if there is still an issue. TestResultWithOutSecondSave.zip (22.6 KB)


#5

Issue is still there in your example. I loaded it and the EndShapeConnectedTo is still NULL. Even in PowerPoint you can observer the issue when you will try to move the group - connector will not follow the group shapes. See screenshot attached

scr1.jpg (65.5 KB)

Can you please try to replicate it in your presentation generated “TestResultWithOutSecondSave” - just drag the group and check what will happen with connector? Maybe it might be related to PowerPoint version, not sure, just will be better to exclude such case

Thank you


#6

@LostAndFound,

I have worked with the sample code shared by you and have been able to observe issue. An issue with ID SLIDESNET-40979 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.