• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Photoshop - replace multiple smart objects - find by name

Guest
Feb 21, 2023 Feb 21, 2023

Copy link to clipboard

Copied

Hi Adobe support community,

Is there a way to replace multiple Smart-objects in Photoshop by selecting one map  on my harddisk (with all the files that needs to be replaced)

Is It possible that Photoshop can find then the same name as in the Smart object and replace the files by name. So multiple Smart-objects need to be replaced with new images in one map on my computer. I Want the script does a find and replace thing.

I hope someone can help me, now I replace all the smart images one-by-one. 

- Select smart object - Replace content - search for the right name and so on for 10 times sometimes in a photoshop file. It is very time-consuming.

I hope someone can help me, you can also send me a message here.
The Screenshot shows all my layers that need te replaced.

For further questions please don't hesitate to send me a message.

Kind regards,

Eline Kouijzer


TOPICS
Actions and scripting , Windows

Views

3.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Feb 21, 2023 Feb 21, 2023

Copy link to clipboard

Copied

You seem to be using the term »map« repeatedly – do you mean a »Folder«? 

 

Could you please post a screenshot of both the image’s Layers Panel and the replacement files in the File Explorer? 

Do the Smart Objects have multiple instances in the document? (Avoiding double-replacing would seem prodent to save time.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 21, 2023 Feb 21, 2023

Copy link to clipboard

Copied

Hi, Thanks for your reply.
Attached an screenshot of my Folder on the computer. The tiff files need to be replaced in the photoshop. Left is the folder and right are the photoshop smart objects that needs to be replaced. 

Some of the smart objects are instances, but I cannot use an instance for reflection.tiff and for Specular.tiff. These are two different files. 


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2023 Feb 21, 2023

Copy link to clipboard

Copied

Another point: Is the folder with the replacement images located at a definitive relative position to the image? (Like there always being a Folder named »renderings« next to the Folder that contains the psd or some such set-up …)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 21, 2023 Feb 21, 2023

Copy link to clipboard

Copied

I have one folder for Renderings (TIFF)

another folder fot the Photoshop files (PSB)

and another folder for the Previews (JPEG, After Photoshop is done on the render)

The render is always the same resolution that need to be displaced, the resolution does not change. Always like 4000x2250px. So this is alwasy the same. 

Then I click the batch file - Replace content - Search for the tiff file (new render). Is it possible that there is a script that can link those words Reflection.tiff for Reflection Smart object in photoshop (has also reflection in the name in photoshop) Find and replace but then by the name of the Tiff file. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 21, 2023 Feb 21, 2023

Copy link to clipboard

Copied

*By displaced i mean Replaced 
*and by the word batch file i mean Smart-object 

(Sorry you cannot change your own post I didn't know untill now.) 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2023 Feb 21, 2023

Copy link to clipboard

Copied

Well … it seems 


Is It possible that Photoshop can find then the same name as in the Smart object and replace the files by name.

was incorrect/incomplete and you don’t want to replace with files of the same name but with ones with progressive numbering somewhere in the name. 

 

What is the complete and exact Folder-structure for one job (the exact names and relative positions of all relevant folders in the job)? 

Please post screenshots to clarify. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 21, 2023 Feb 21, 2023

Copy link to clipboard

Copied

"was incorrect/incomplete and you don’t want to replace with files of the same name but with ones with progressive numbering somewhere in the name"
To reply on this one, it is correct. Reflection_V04.tiff needs to be replaced for Reflection_V05.tiff
See screenshots. I hope this will clarify the problem.
I have some things blurred, it is for a client. Thats what some text is blurred. Sorry for that. But the main problem is that I need to do this for every pass (Reflection, Specular and so on) All my renders-passes needs to be replaced. From Version 4 to Version 5. I have like 10 Render elements in my Photoshop file. So I really want to have a script that can do this. (Replace content for these file in Photoshop)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2023 Feb 21, 2023

Copy link to clipboard

Copied

I see no problem in a Script that replaces Smart Objects with progressively numbered tiffs (though I might not get to posting code soon) but we do not seem to be communicating successfully. 

 

I want to know what the exact relative positions of the folders containing the psb and the tiff-files are. 

Because manually selecting the Folder containing the Renderings each time they need updating would seem wasteful. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 21, 2023 Feb 21, 2023

Copy link to clipboard

Copied

"I want to know what the exact relative positions of the folders containing the psb and the tiff-files are. "

 

See the attached screenshot.

PSB: 
"E:\3DS-Max\PHOTOSHOP\Cam_05\Cam_05.psb"

TIFF(Render passes): 
"D:\RENDERS\Cam_05\Cam05_V05.VRayReflection.0000.tif"
"D:\RENDERS\Cam_05\Cam05_V05.VRaySpecular.0000.tif"

I don't know if it is better to work with UNC-names now? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2023 Feb 21, 2023

Copy link to clipboard

Copied

You can give this a try, you need to amend theTifFolder, though, to the position on your D-Drive. 

In my test with this Folder-structure 

Screenshot 2023-02-21 at 17.42.08.png

I get these updates:

Screenshot 2023-02-21 at 17.42.42.pngScreenshot 2023-02-21 at 17.42.53.png

// replace smart objects with tif with number plus one;
// 2023, use it at your own risk;
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
// get renderings folder;
if (myDocument.name.indexOf(".") != -1) {var myDocName = myDocument.name.match(/(.*)\.[^\.]+$/)[1]}
else {var myDocName = myDocument.name};
try {var myPath = myDocument.path}
catch (e) {var myPath = "~/Desktop"};
var theTifFolder = Folder(Folder(myPath).parent+"/renderings");
// collect smart objects;
var theSmartObjects = collectSmartObjects2017();
var theRegExp = /_Cam\d{2}\.VRay/i;
// work through smart objects;
for (var m = 0; m < theSmartObjects.length; m++) {
    var theMatch = theSmartObjects[m][0].match(theRegExp);
    if (theMatch != null) {
        var theReplace = theSmartObjects[m][0].replace(theRegExp, "_Cam"+bufferNumberWithZeros(Number(String(theMatch).match(/\d{2}/))+1, 2)+".VRay");
        if (File(theTifFolder+"/"+theReplace+".tif").exists == true) {
// replace smart object it matching tif exists;
            replaceContents (File(theTifFolder+"/"+theReplace+".tif"), theSmartObjects[m][1]);
        };
    }
};
};
////////////////////////////////////
////// collect smart objects, probably based on code by paul, mike or x //////
function collectSmartObjects2017 () {
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if not layer group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
if(layerDesc.hasKey(stringIDToTypeID('smartObject'))) {theLayers.push([theName, theID])}
};
}
catch (e) {};
};
return theLayers
};
////// replace contents //////
function replaceContents (newFile, theSOId) {
selectLayerByID(theSOId, false);
// =======================================================
var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc3.putPath( idnull, new File( newFile ) );
var idPgNm = charIDToTypeID( "PgNm" );
desc3.putInteger( idPgNm, 1 );
executeAction( idplacedLayerReplaceContents, desc3, DialogModes.NO );
return app.activeDocument.activeLayer
};
// based on code by mike hale, via paul riggott;
function selectLayerByID(id,add){ 
add = undefined ? add = false:add 
var ref = new ActionReference();
    ref.putIdentifier(charIDToTypeID("Lyr "), id);
    var desc = new ActionDescriptor();
    desc.putReference(charIDToTypeID("null"), ref );
       if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) ); 
      desc.putBoolean( charIDToTypeID( "MkVs" ), false ); 
   try{
    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message); 
}
};
////// buffer number with zeros //////
function bufferNumberWithZeros (number, places) {
	var theNumberString = String(number);
	for (var o = 0; o < (places - String(number).length); o++) {
		theNumberString = String("0" + theNumberString)
		};
	return theNumberString
	};

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 21, 2023 Feb 21, 2023

Copy link to clipboard

Copied

Thank you very much for the scripting! Really nice!


I have tried several times the script. It doesn't work. But I don't know exactly if I changed the name well, could you please tell me where exactly in the code I need to change the TIFF-folder name to my "D:\RENDERS\Cam_05" (D-Drive where the Renders are)

How does the script actually work? Does it look at the name in my renderings? I saw you use the word V-Ray as last word and then the number that counts up? I always need to have the word "V-Ray" in the text of the render? It doesn't matter how much characters have the render name (TIFF-File)?

 

The script does not count the characters? It looks for the word Vray and then it counts for version 4 and replace with version 5?  So I should always have the word "V-Ray" in the TIFF-File? (like "Reflection-V-Ray_V05.tiff" Or can it also be "Reflection-V05.tiff"?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2023 Feb 21, 2023

Copy link to clipboard

Copied

I am a Mac-user so Windows naming conventions are lost on me. 

But please try "D:/RENDERS/Cam_05"

Or use 

// thanks to xbytor;
var theDocument = Folder.selectDialog("select a folder");
// for folders;
var thePath = theDocument.path;
var theName = theDocument.name;
var theString = theDocument.absoluteURI;
while (theString.indexOf("%20") != -1) {
   theString = theString.replace("%20", " ")
  };
alert (theString);

to make sure how the Folder’s path needs to be written. 

 

The Script checks the names of the Smart Objects for »_CamXX.VRay« (with XX being numbers), adds one to the number and then looks for the corresponding tif in theTifFolder. 

If that is not the general naming convention what is it? How can one unequivocally identify the actual numbers in the Smart Object/tif-name that are supposed to count up? 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 22, 2023 Feb 22, 2023

Copy link to clipboard

Copied

Thanks for your reply, no matter what I do I cannot get it done. It doesn't replace anything.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2023 Feb 22, 2023

Copy link to clipboard

Copied

Please provide the files for testing. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 22, 2023 Feb 22, 2023

Copy link to clipboard

Copied

LATEST

I sent you a personal message. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines