How to replace embedded ai smart object

Hello, I am trying to find a way to replace an embedded ai smart object in a psd file. Is that even possible? If so, how could I go about doing it. I tried the following:

        try (PsdImage psdTemplate = PsdImage.load(new ByteArrayInputStream(psdBytes)); AiImage aiDesign = AiImage.load(new ByteArrayInputStream(aiBytes))) {
            SmartObjectLayer smartObjectLayer = psdTemplate?.getLayers()?.find {it?.name == "Art-1" && it instanceof SmartObjectLayer }
            smartObjectLayer.replaceContents(aiDesign)
            psdTemplate.getSmartObjectProvider().updateAllModifiedContent()
            psdTemplate.save("/Users/rtom/Documents/result.png", new PngOptions(colorType: PngColorType.TruecolorWithAlpha))
        }

However, I got an exception when replaceContents() was called saying, “com.aspose.psd.fileformats.ai.AiImage.saveData: The method or operation is not implemented”

@rtom
@rtom unfortunately at this moment it’s impossible to use AiImage in the SmartObjectLayer. But Aspose.PSD Team actively work on the editing, creating from scratch and saving of AiImage, so, it’s possible that it will be made in 3 months.

Could you please additionally provide input file for testing to give us ability to check not only replacing AiImage SmartObject, but also that your files can be rendered.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PSDJAVA-607,PSDNET-1990

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@Dmitriy.Sorokin - Thanks for the quick reply! Would it be possible to to this with a png (or some other format) instead of an ai file? If so, is there documentation with an example?
2-DH002.ai.zip (1.1 MB)

@rtom Thank you for the input file. I’ve added it to the created issues.

Your code should work fine with other formats.
Please check the following documentation page: Smart Object Update and Export using Aspose.PSD for Java|Documentation

The main difficulty can be in the process of loading PNG, JPEG, TIFF, BMP, GIF images:
They should be loaded using SmartObjectLayer | Aspose.PSD for Java API Reference

or you need to load these formats using Layer API as in this article: Aspose.PSD Add Layer From File|Documentation here is example:

 try (InputStream inputStream = Files.newInputStream(Paths.get(inputFile))) 
 {
         // Create PSD Layer from InputStream
         Layer layer = new Layer(inputStream);

Then you can replace contents of SmartObject by the opened layer.