Skip to main content
Known Participant
January 10, 2018
Question

How to access the contents of a Smart object....

  • January 10, 2018
  • 1 reply
  • 3616 views

So ultimately this is what I'm trying to do:

I'm trying to make the life of my client easier. I want to give them a photoshop file that has a smart object manipulated to fit a design. I want the client to be able to just run a script that will change the image that is in that smart object to a new image.

So this is going to look really hacky I'm sure but this is where I'm at:

var fileRef1 = File(Folder.desktop.fsName + "/Image-1/new-image.png");

var docRef1 = app.open(fileRef1);

docRef1.artLayers["Background"].copy();

var fileRef2 = File(Folder.desktop.fsName + "/Image-1/image-1.psd")

var docRef2 = app.open(fileRef2)

docRef2.paste();

Running that opens all the images I required and copy and pastes the png into the PSD. Now if only could paste that image into the PSB file instead! The smart object layer is named "ScreenContents"

Any thoughts?

This topic has been closed for replies.

1 reply

jdingwellAuthor
Known Participant
January 10, 2018

Follow up info....

The PSD will not be changed so I will always have control and access to layer names. The 'new' image is being exported from Sketch (an application screen) and I can force a naming convention for this file.

My assumption is that I will give my client a folder with the PSD in it which they will put on their desktop. They will export a new image out of Sketch and place that png in the folder then run the script.

JJMack
Community Expert
Community Expert
January 10, 2018

It is more like you want to replace the object content.

If you want the user to be able to use any image as a replacement you have to design the PSD well.  You can not simple replace the smart object layer's object  with any size image.  You would need to delete the smart object layer and place in a new one transforms for fit and mask to shape.

All smart object layer have and associated transform.    You can replace the object content  only with and image that is the same size and resolution as the original image object.  The Associated transform is not replaced or altered when you replace a smart object layer's  object.  If the object is not the same size and resolution you have a problem.

In my Photo Collage Toolkit my PSD template design has an alpha channel for each image's location size and shape shape.   There are no image layers in my template PSD design].   A populated  collage can have an image replaced by a script in the toolkit because of the template design the script knows which image is being replaced from the layer level in the layer stack, know which alpha channel maps the image location size and shape. The script simply delete the Placed ins smart object layer then placed in the replacement image  transform for fit and mask to shape. Using the Alpha channel for the image.

The problem with my design  is it that my scripts can not handle things like image rotation and perspective distortion.  Image are place in squared to the canvas and resize in a constrained way no distortion  like perspective can be automated.   Normally that is what you want.   My scripts always save populated collages as layered PSD file.   So you can if needed manually  change a placed image smart object transform to add rotation and distortion like perspective.

Photo Collage Toolkit

Photoshop scripting is powerful and I believe this package demonstrates this here is a video showing a 5 image collage PSD template  being populated with images

The package includes four simple rules to follow when making Photo Collage Template PSD files so they will be compatible with my Photoshop scripts.

  1. Size the photo collage templates for the print size you want - width, height and print DPI resolution.
  2. Photo collage templates must have a Photoshop background layer. The contents of this layer can be anything.
  3. Photo collage templates must have alpha channels named "Image 1", "Image 2", ... "Image n".
  4. Photo collage templates layers above the background layers must provide transparent areas to let the images that will be placed below them show through.

There are fifteen scripts in this package they provide the following functions:

  1. HelpPhotoCollageToolkit.jsx - Online Help
  2. TestCollageTemplate.jsx - Used to test a Photo Collage Template while you are making it with Photoshop.
  3. CollageTemplateBuilder.jsx - Can build Templates compatible with this toolkit's scripts.
  4. LayerToAlphaChan.jsx - Used to convert a Prototype Image Layer stack into a template document.
  5. InteractivePopulateCollage.jsx - Used to interactively populate Any Photo Collage template. Offers most user control inserting pictures and text.
  6. ReplaceCollageImage.jsx - use to replace a populated collage image Smart Object layer with an other image correctly resized and positioned.
  7. ChangeTextSize.jsx - This script can be used to change Image stamps text size when the size used by the populating did not work well.
  8. PopulateCollageTemplate.jsx - Used to Automatically populate a Photo Collage template and leave the populated copy open in Photoshop.
  9. BatchOneImageCollage.jsx - Used to Automatically Batch Populate Collage templates that only have one image inserted. The Collage or Image may be stamped with text.
  10. BatchMultiImageCollage.jsx - Used to Automatically Batch Populate Any Photo Collage template with images in a source image folder. Easier to use than the interactive script. Saved collages can be tweaked.
  11. PasteImageRoll.jsx - Paste Images into a document to be print on roll paper.
  12. BatchPicturePackage.jsx - Used to Automatically Batch Populate Any Photo Collage template with an image in a source image folder.  Images Rotates for best fit.
  13. BatchPicturePackageNoRotate.jsx - Used to Automatically Batch Populate Any Photo Collage template with an image in a source image folder.
  14. PopulatePicturePackage.jsx - Used to Automatically populate a Photo Collage template Fill with the same single image and leave the populated copy open in Photoshop.
  15. PCTpreferences.jsx - Edit This File to Customize Collage Populating scripts default setting and add your own Layer styles.

Documentation and Examples

JJMack
jdingwellAuthor
Known Participant
January 11, 2018

Thank you for your thorough reply. I'm not sure if that is exactly what I'm looking for.

In my case, the image will always be the exact dimensions so it is the perfect candidate for a simple image swapping or even pasting into the PSB (it doesn't matter if the original image is deleted since the new image will completely cover the previous one - and if necessary, the PSB can be culled every now and then by a design resource if it has too many layers)

Take a look at the image below, hopefully this will give you some better reference of what I'm trying to do.

The purple 'app screen' image is a smart object that has been distorted to fit the perspective of the iPhone. Each application screen will be exactly the same size.

Any thoughts? Is there no way to have photoshop 'open' a smart object layer and then manipulate the resulting PSB file?