How to Find Stable Unique Identifier of Shape Object in Presentation?

Dear Aspose,

Please help us find stable unique identifier of shape object.

When using UniqueId property of shape object in Presentation this value changes based on shape order and due to that behavior, we can not rely on such identifier.

Unfortunately, Name stays the same even after Copy-Paste and brings us ambiguity problem.

Please see the attached image and code in zip file showing unstable Shape.UniqueId.
Bug-56121-DuplicateObjectRendered.zip (151.6 KB)
BUG-56121-DuplicateObjectRendered.png (70.0 KB)

Kind Regards
Pavel

@ottap,
Thank you for contacting support.

Please do not share license files in forum threads in the future. I’ve deleted your license data from the zip file. We will reply to you as soon as possible.

@ottap,
To help me better understand the issue, could you please describe in more detail some cases and expected behavior for the UniqueId property?

Hi Andrey,
we were looking for unique persistent identifier of shape object in presentation - so we can store “link” to such shape (and link to the file) to load it in future using that link / shortcut - even if the content is updated.

After some investigation it seems Shape.OfficeInteropShapeId is acting exactly what we need and we can use it in PPT.

Any idea what can provide us same behavior with respect to Aspose.Cells / Charts ?

Thanks for answer.

@ottap,
We are glad to know that you have found the solution. As for Aspose.Cells, you should describe the issue and requirements on Aspose.Cells forum.

Hi Andrey,
I would like to ask few questions about best Shape identifier.

What would you recommend as most stable, persistent, reliable Shape identifier (considering ppt file will be edited)?

Does Shape.OfficeInteropShapeId stay unchanged once set for object in PPT sheet and works both on Windows and Linux the same / are there any limitations (cases when it is being changed)?

Potentially is that best identifier of object in the slide?

For example, as mentioned above, we were not able to use Shape.UniqueId since after adding new object or deleting other and reshuffling them many old shapes obtained different UniqueIds.

Shape.Name had another issue / it could be duplicated and sometime is just by copy-pasting.

Is there any other / better way to identify object then OfficeInteropShapeId?

Best Regards
P.

@ottap,
I need some time to find out information for you. We will reply to you as soon as possible.

@ottap,
The UniqueId property specifies a unique identifier for a shape in presentation scope. Whereas the OfficeInteropShapeId property specifies a unique identifier for a shape in slide scope. Could you please clarify if your presentations will be edited in PowerPoint and other applications or only with Aspose.Slides?

Hi Andrey,
our PPT presentation will be edited in PowerPoint for Desktop or PowerPoint Online only.

As mentioned above - we found out that UniqueId is not persistent.
For example : If you add new shapes and delete some in the middle of your presentation since new UniqueId will be assigned to each Shape starting 1 with step +1 (no gaps) through all the presentation - some UniqueIds tents to vary - so shape with UniqueId 17 could now have UniqueId 14 for example (so if you were targeting shape by UniqueId=17 now you are obtaining different shape).

On the other hand OfficeInteropShapeId behaves much better and adding / deleting shapes on the slides does not change OfficeInteropShapeIds already assigned (unfortunately there can be the very same OfficeInteropShapeId for more slides)

So we can not rely on just OfficeInteropShapeId to identify the shape in whole presentation.

Best what we found in the moment is combination of SliedeId and OfficeInteropShapeId (it breaks when you move Shape to another slide).

Is not there anything like createId property for PPT Shapes like it is for excel charts according to this answer:

?

Thanks for answer.

Best Regards
P.

@ottap,
I think there can’t be two shapes with the same UniqueId in a presentation and two shapes with the same OfficeInteropShapeId in a slide, but this is where their responsibility ends. Because they can change, they really can’t be relied upon. I’ve added a ticket with ID SLIDESNET-43249 to our issue tracking system. Our development team will consider implementing support for CreationId property. You will be notified when the issue is resolved.

Hi Andrey,
would like to ask about the progress with SLIDESNET-43249 CreationId property for PPT shapes.

Refering to your note: Our development team will consider implementing support for CreationId property.

Since we noticed there is no such property available still in Aspose.Slides.22.7.

Thanks

Kind Regards
Pavel

@ottap,
I requested information from our developers for you.

@ottap,
Adding such a property is planned for Aspose.Slides 22.9. Thank you for your patience.

@ottap,
Our developers are still working on the issue, and the required propery will not appear in version 22.9 (ETA was moved to 22.10), but there is a way to generate a stable unique id for each shape like this:

private const string SHAPE_UNIQUE_ID_NAME = "MyShapeUniqueId";

public static void Main()
{
    using Presentation pres = new Presentation("pres.pptx");

    Aspose.Slides.LowCode.ForEach.Shape(pres, (shape, slide, index) =>
    {
        shape.CustomData.Tags.Add(SHAPE_UNIQUE_ID_NAME, Guid.NewGuid().ToString("N"));
    });

    foreach (ISlide slide in pres.Slides)
    {
        foreach (IShape shape in slide.Shapes)
        {
            Console.WriteLine(shape.GetUniqueId());
        }
    }

    pres.Save("pres-unique-ids.pptx", SaveFormat.Pptx);
}

public static string GetUniqueId(this IShape shape)
{
    return shape.CustomData.Tags[SHAPE_UNIQUE_ID_NAME];
}

Please let us know if the solution is suitable for you.

@ottap,
We apologize for misleading. OfficeInteropShapeId is a unique identifier. This ID can be used to assist in uniquely identifying this object so that it can be referred to by other parts of the document.

UniqueId is an internal (programmable) identifier of the object and can be reassigned by the user to use it in internal applications or PowerPoint Add-ins. Since this parameter can be installed by the user (and in this very presentation this is take place), this identifier is not unique.

We will improve the description of OfficeInteropShapeId and UniqueId properties later.

The issues you found earlier (filed as SLIDESNET-43249) have been fixed in Aspose.Slides for .NET 23.1 (ZIP, MSI).
You can check all fixes on the Release Notes page.
You can also find the latest version of our library on the Product Download page.