Working with smart objects

Hi
Is any example how to work with photoshop smart objects?
I have psd with 2 smarts objects, I need change text there, then need generate image with new text in smart objects with saving all effects like overlay, stroke
I try to find any example with smart objects but cant find

@aspose_psd

You may please consider using following example on your end for working with Smart objects.

 public void Test1Smart()
        {
            var filePath = @"mySmartObjectTest.psd";
            var newContentPath1 = @"smartReplace1.png";
            var newContentPath2 = @"smartReplace2.png";

            var pngOutputPath = @"pngoutput.png";
            var psdOutputPath = @"psdoutput.psd";
            using (PsdImage image = (PsdImage)Image.Load(filePath))
            {
                for (int i = 0; i < image.Layers.Length; i++)
                {
                    if (image.Layers[i].GetType().Name.Contains("SmartObjectLayer"))
                    {
                        SmartObjectLayer smartObjectLayer = (SmartObjectLayer)image.Layers[i];

                        if (i % 2 == 1)
                        {
                            smartObjectLayer.ReplaceContents(newContentPath1);
                        } else
                        {
                            smartObjectLayer.ReplaceContents(newContentPath2);
                        }
                    }
                }

                image.Save(pngOutputPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                image.Save(psdOutputPath, new PsdOptions(image));
            }
        }

I need change text in smart object not image

@aspose_psd

I actually provided the sample to access and work with smart object layer. Please provide the source file and required output file and we will try to help your further in this regard.

Get error
Error CS0246 The type or namespace name ‘SmartObjectLayer’ could not be found
Download Aspose.PSD for .NET 20.11 (Dlls only)
Try version 4.0, 3.5, 2

@aspose_psd

Can you please share your example project and source file that I may refer on my end to help you further.

I use this example Working with smart objects - #2 by mudassir.fayyaz
Here is my list of using
using Aspose.PSD;
using Aspose.PSD.FileFormats.Psd;
using Aspose.PSD.FileFormats.Psd.Layers.SmartObjects.SmartObjectLayer; //not work for me

@aspose_psd

Please check this API reference guide link. This should work on your end. Can you please provide a working sample Visual Studio project that we may observe on our end to assist you further.

1.zip (4.8 MB)
Here is test psd with 2 smart objects C and D
How Change text on it?
I search through Class SmartObjectLayer | Aspose.PSD for .NET API Reference but nothing for work with text

@aspose_psd

Can you please explain if you are still facing following issue as in your last post you have referred to requirement of changing text.

It works now and I try to update text in smart object

@aspose_psd

We are working over this on our end and will get back to you with feedback as soon as possible.

the library not support editing text in smart objects?

@aspose_psd

Can you please consider using following sample code on your end.

PSDNET787.zip (201.2 KB)

here is my modify code+data1.zip (5.4 MB)
the result image looks worse than psd origin

@aspose_psd

We are looking into this and will get back to you with feedback after investigation.

@aspose_psd

After investigation we have observed some issue in your example and suggest to uset following:

  1. To use effects, you should be using the following load options:
using (PsdImage image = (PsdImage)Image.Load(srcFile, new PsdLoadOptions() { LoadEffectsResource = true }))
  1. You should change size of text if you want to make image to look fine.
                                        var textData = textLayer.TextData;

                                        textData.Items[0].Text = "Best";
                                        textData.Items[0].Style.FontSize = 170;
  1. When layer effects are loaded and we try to render image and have the blending issue in case of multiple layers. A ticket with ID PSDNET-789 has been created to investigate and resolve this.

when I use this line I get error
NullReferenceException: Object reference not set to an instance of an object.

with this code
image.Save(“result.png”, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });

@aspose_psd

This seems to be a separate issue in API. A ticket with ID PSDNET-792 has been created 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.

Is it possible to achieve my goal with editing text in smart objects?