Script to replace Smart Objects in Photoshop files

May 15th, 2013

Wanting to share graphical assets between multiple Photoshop files and update them at once just like when linking images to Illustrator files, I wrote a script that can replace Smart Object layers with external .psb files. This actually is my first Photoshop script. Any suggestions for improvements would be much appreciated.

How to use it:

  1. Install the script, place the .jsx file in the Scripts folder (Photoshop CS/Presets/Scripts) and restart the application. The script appears in the Scripts menu (File > Scripts)
  2. Create the graphical assets as .psb files and save them in a folder named “assets”
    The file names must start with the prefix “so_” and end with “.psb”. (the folder name and the prefix can be altered in the variables in the beginning of the code.)
  3. In the psd(b) files in which you want to use these assets, create Smart Object layers that have the same names as .psb files without the extension, e.g. a layer named “so_mail_icon” links to assets/so_mail_icon.psb.
  4. Run the script. The smart layers will be replaced with the .psb files.

Download Sample

var prefix = "so_";
var assetPath = "assets/"

var count = 0;
listLayersets(app.activeDocument);
listLayers(app.activeDocument);
var path;

function listLayersets(pointer) {
     for (var i = 0; i < pointer.layerSets.length; i++) {
        var layerset = pointer.layerSets[i];
        listLayers (layerset);
    }
}

function listLayers(pointer) {
    for (var i = 0; i < pointer.artLayers.length; i++) {
        var layer = pointer.artLayers[i];
        if (layer.name.indexOf(prefix) == 0) {
            if (layer.kind == "LayerKind.SMARTOBJECT") {
                app.activeDocument.activeLayer = layer;
                replaceSO (app.activeDocument.path + "/" + assetPath + layer.name + ".psb");
            }
         }
    }
}

function replaceSO (newFile) {
	var id = stringIDToTypeID( "placedLayerReplaceContents" );
    var desc = new ActionDescriptor();
    var idn = charIDToTypeID("null");
    desc3.putPath( idn, new File(newFile));
    var idp = charIDToTypeID("PgNm");
    desc3.putInteger(idp, 1);
	executeAction(id, desc, DialogModes.NO);
	return app.activeDocument.activeLayer
};

Stardusts and boxes

May 8th, 2013

Hand-drawn boxes crush and be brown into stardust, plus some more experiments with ofCamera.

stardusts and boxes from kynd on Vimeo.

stars from kynd on Vimeo.

color stars from kynd on Vimeo.

Ecdysis

April 29th, 2013

Ecdysis of a box shaking off its skins to leave nothing other than empty space.

ecdysis from kynd on Vimeo.

blowing out papers

April 27th, 2013

Quick sketches with openFrameworks that simulate the physics of fragile objects looking like both paper and water. The motion of the polygons is based on verlet integration, and the pieces are tied with weak bonds that breaks if a certain force to tear it apart is given. The second piece reminded me of Saburo Murakami’s, said to be, avant-garde performance where he broke a series of papers by running his body into them.

paper balls blowout from kynd on Vimeo.

paper planes blowout from kynd on Vimeo.

paper planes blowout (colored) from kynd on Vimeo.

Related Posts with Thumbnails