docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Use case: Read an attachment in an annotation

    Before you start

    Before you read an attachment, ensure you have completed the following prerequisites:

    1. Verify Permissions: Confirm that you have the necessary rights to read annotations.
    2. Existing Annotation: You must have an existing annotation containing the attachment to read.
    3. Existing Attachment's identifier: You must have an existing attachment's ID to read.

    How do I...?

    Read an attachment

    There is not a specific API call for reading an attachment. Instead, you can use the ReadAnnotationAsync method to read the annotation and its attachments. This method returns an IAnnotation object that contains the attachment(s) you want to read in its Attachments property. You can find the attachment you want to read by its ID in the Attachments collection.

    var attachmentId = new AttachmentId("<attachment-id>");
    var annotation = await User1Manager.AnnotationManagement.ReadAnnotationAsync(m_CreatedAsset.Descriptor.ProjectId, m_createdRootAnnotationId);
    var attachment = annotation.Attachments.SingleOrDefault(x => x.AttachmentId == attachmentId);
    

    Please note that the Attachments collection contains a collection of IAttachment objects. To read a specific type of attachment, or to access the properties of a specific type of attachment, you can use the OfType extension method.

    var fileAttachmentId = new AttachmentId("<file-attachment-id>");
    var fileAttachment = annotation.Attachments.OfType<IFileAttachment>().SingleOrDefault(x => x.AttachmentId == fileAttachmentId);
    
    var spatialAttachmentId = new AttachmentId("<file-attachment-id>");
    var spatialAttachment = annotation.Attachments.OfType<ISpatial3DAttachment>().SingleOrDefault(x => x.AttachmentId == spatialAttachmentId);
    
    var sketchAttachmentId = new AttachmentId("<file-attachment-id>");
    var sketchAttachment = annotation.Attachments.OfType<ISketchAttachment>().SingleOrDefault(x => x.AttachmentId == sketchAttachmentId);
    

    Get the file path of a file attachment

    var fileAttachmentId = new AttachmentId("<file-attachment-id>");
    var fileAttachment = annotation.Attachments.OfType<IFileAttachment>().SingleOrDefault(x => x.AttachmentId == fileAttachmentId);
    
    var filePath = fileAttachment.FilePath;
    

    or

    var attachment = annotation.Attachments.SingleOrDefault(x => x.AttachmentId == attachmentId)
    var fileAttachment = attachment as IFileAttachment;
    if (fileAttachment != null)
    {
        var path = fileAttachment.FilePath;
    }
    

    Follow the same approach to read type-specific properties of other types of attachments.

    For more information on working with attachments, see the documentation on creating attachments, updating attachments and deleting attachments.

    See the API documentation for more details on the ReadAnnotationAsync method.

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)