ExtendScript Photoshop Edit Contents Smart Layer

New Here ,
Oct 31, 2019

Copy link to clipboard

Copied

I have a psd file with an embedded psd file. Using photoshop normally, I double on the layer icon to edit the contents (or choose "edit contents" from the dropdown). I can not seem to find out how to open/edit it with extendscript/javascript. It is a legend that we use on our plans and would like to add content via scripting but need to find out how to edit the contents first. Note: this is not a linked file externally, it is embedded.

Thanks in advance.

Adobe Community Professional
TOPICS
Actions and scripting, Problem or error

Views

1.5K

Likes

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

ExtendScript Photoshop Edit Contents Smart Layer

New Here ,
Oct 31, 2019

Copy link to clipboard

Copied

I have a psd file with an embedded psd file. Using photoshop normally, I double on the layer icon to edit the contents (or choose "edit contents" from the dropdown). I can not seem to find out how to open/edit it with extendscript/javascript. It is a legend that we use on our plans and would like to add content via scripting but need to find out how to edit the contents first. Note: this is not a linked file externally, it is embedded.

Thanks in advance.

Adobe Community Professional
TOPICS
Actions and scripting, Problem or error

Views

1.5K

Likes

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
Oct 31, 2019 1
Adobe Community Professional ,
Oct 31, 2019

Copy link to clipboard

Copied

One way:

 

app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));

 

https://community.adobe.com/t5/Photoshop/Script-to-Export-Contents-of-all-Smart-Objects-in-a-Photosh...

Likes

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
Reply
Loading...
Oct 31, 2019 0
New Here ,
Nov 01, 2019

Copy link to clipboard

Copied

Thanks Stephen & JJmack, answer was right in front of me in the code but couldn't see it through the forest.

Likes

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
Reply
Loading...
Nov 01, 2019 0
Most Valuable Participant ,
Oct 31, 2019

Copy link to clipboard

Copied

A PSD Object will open in Photoshop and your script will still be in cintrol of Photoshop and can edit the opened object. However, you need to be careful opening Smart Object Layers contents using A Photoshop script.  There are many ways smart object layers are created. All smart Object Layers's Object are not Photoshop Objects.  If you open them in a Photoshop script they will open in other applications or a Photoshop ACR Plug-in. The Photoshop script that opened the object  will lose control till the Application or pug-in execution finishes The script can not edit such objects.   R-bin posted code you can use to test the type object a smart object contains.  To determine if the object will open in Photoshop or not. I use that code in my Batch Photoshop Mockups scripts when the user want toe edit object rather than replace smart object layer object using replace content.   My scripts can not handle editing Mockup templates smart object layers that have none Photoshop object. Only replace content is supported  for none when Smart Object layer have none Photoshop Objects.

 

 

 

 


function objectIsPsObject(SOlayer) {
	//Thanks to r-bin
	var ext = smartobject_file_ext(SOlayer);  
    var rc = true;
	switch (ext)  
		{  
		case "nef":  
		case "cr2":  
		case "crw":  
		case "raf":  
		case "orf":  
		case "mrw":  
		case "dcr":  
		case "mos":  
		case "raw":  
		case "pef":  
		case "srf":  
		case "dng":  
		case "x3f":  
		case "erf":  
		case "sr2":  
		case "kdc":  
		case "mfw":  
		case "mef":  
		case "arw":  
		case "nrw":  
		case "rw2":  
		case "rwl":  
		case "iiq":  
		case "3fr":  
		case "fff":  
		case "srw":  
		case "ai":
		case "svg":
		case "pdf":
		case "esp":
			rc = false.	
			break;  
		case "error":  
			rc = false;
			break;         
  		default:  
			rc = true;
			break;  
    }  
	return rc;
}

 

 

 

 r-bin code 

JJMack

Likes

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
Reply
Loading...
Oct 31, 2019 1
Adobe Community Professional ,
Oct 31, 2019

Copy link to clipboard

Copied

JJMack, the code as posted does not work...

 

When I add:

 

objectIsPsObject();

 

An error is returned from your posted code:

 

Runtime Error: Error Code# 24: smartobject_file_ext is not a function on the following code entry:
 
var ext = smartobject_file_ext(SOlayer);

Likes

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
Reply
Loading...
Oct 31, 2019 0
Most Valuable Participant ,
Oct 31, 2019

Copy link to clipboard

Copied

Correct you need to pass a smart object layer object to the function. You did not pass a smart object layer. If you pass a smart object layer the  function will return true if the layer object work file extension will open in photoshop or false if the object will not open in Photoshop. 

 

function objectIsPsObject(SOlayer) {

...

JJMack

Likes

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
Reply
Loading...
Oct 31, 2019 0
Adobe Community Professional ,
Oct 31, 2019

Copy link to clipboard

Copied

Thanks, as I mostly hack at scripting, this is not immediately "plug-n-play" and I'll have to play a bit to try to make this work without a working sample.

Likes

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
Reply
Loading...
Oct 31, 2019 0
Most Valuable Participant ,
Nov 01, 2019

Copy link to clipboard

Copied

Working sample Batch Mockup Scripts of its use it is plug and play as posted I use copy paste to post it.

JJMack

Likes

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
Reply
Loading...
Nov 01, 2019 0
Adobe Community Professional ,
Nov 02, 2019

Copy link to clipboard

Copied

Thanks JJ, I have kicked this around without success. This is due to my current knowledge level (or lack thereof), not your code.

 

With a (psb) smart object layer active, the single line of code that I previously posted opens the smart object layer.

 

I have not had the same successful result using the code from r-bin. I even tried adding PSD and PSB into the list of extensions, however that is probably not the issue.

 

By "plug n play" I meant that the code should be complete and concise to do exactly what is required without any further editing.

Likes

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
Reply
Loading...
Nov 02, 2019 0
Most Valuable Participant ,
Nov 02, 2019

Copy link to clipboard

Copied

The function is complete.   A function is not a complete script. And your one line has problems it will work only if the active layer is a smart object layer and the object is supported by photoshop.  It will fail in all other cases. Here no active layer and also with an  active layer that is a smar object layer with an object that photoshop does not support. In the case vector smart object. That object opened in Chrome on my machine. It an SVG file create by Adobe AI.

Capture.jpg

 

 

The code does not open open a smart object layer's object.  The code test a smart object layer to see if you use open smart object layer object to open the object into Photoshop.   If you pass your smart object layer that has a PSB object it would return true you can.   Your line of code  edits Photoshop active document active layers smart object. 

 

 

 

 

app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));

 

 

 

 

There are problems with that if not user properly. If the active layers is not a smart object layers the lines will through a script error. If the active layers is a smart object layers and the object is not a Photoshop supported object it will not fail. However, the script will lose control  and not be able to edit the object for it will not open in Photoshop. An other Application like AI or a Plug-In like ACR will be what open the object not Photoshop. If you know active layer is a smart object layer and the layer's object is a Photoshop object your code will work.  I your not sure of what kind of object the smart object is you need r-bin code or your script will fail its Murphy's law.

Your one line should be a if statement. With or without the else.

 

 

 

 

if (objectIsPsObject(activeDocument.activeLayer)) app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
else alert(activeDocument.activeLayer.name + " Object can not be edited using Photoshop its unchanged.");

 

 

 

I do not know JavaScript or Photoshop Scripting. I do have a programming background so I hack  at code.  You are learning you need to read more code to get a better understanding of what is what. It should not be hard for you read that function to see all it does is return True or False. 

 

JJMack

Likes

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
Reply
Loading...
Nov 02, 2019 0
Most Valuable Participant ,
Nov 02, 2019

Copy link to clipboard

Copied

We all make mistakes and I did forget to paste the inner function smartobject_file_ext. So you were right when you posted the code I posted does not work.  So here is a  script your one line script to open Photoshop active layers smart object layer object in  Photoshop for editing. The code to edit the object is not included. However. That code should end with a Close that Saves the edits. So the opened work file will  closed out of Photoshop so the active document will become the original current document  Its Active Smart object layer's  object will be updated and new pixels rendered for the layers content.  As the Script stands there will be at least two open documents in Photoshop when it ends. The original document you ran the script from and the opened temp work document. Should] the object be a Photoshop object.

 

 

if (!documents.length) alert('There are no documents open.', 'No Document');
else {
   if (app.activeDocument.activeLayer.kind!=LayerKind.SMARTOBJECT) alert("ActiveLayer not Smart Object Layer");
   else {
      if (!objectIsPsObject(activeDocument.activeLayer)) alert(activeDocument.activeLayer.name + " Object can not be edited using Photoshop its unchanged.");
      else app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
      // Add code here to edit the smart object temp work file

     // Close the work file with save to clost the temp wok file out of Phtoshop and have Photoshop updater the orifinals smart object layers objeyy
   }
}

function objectIsPsObject(SOlayer) {
	//Thanks to r-bin
	var ext = smartobject_file_ext(SOlayer);  
    var rc = true;
	switch (ext)  
		{  
		case "nef":  
		case "cr2":  
		case "crw":  
		case "raf":  
		case "orf":  
		case "mrw":  
		case "dcr":  
		case "mos":  
		case "raw":  
		case "pef":  
		case "srf":  
		case "dng":  
		case "x3f":  
		case "erf":  
		case "sr2":  
		case "kdc":  
		case "mfw":  
		case "mef":  
		case "arw":  
		case "nrw":  
		case "rw2":  
		case "rwl":  
		case "iiq":  
		case "3fr":  
		case "fff":  
		case "srw":  
		case "ai":
		case "svg":
		case "pdf":
		case "esp":
			rc = false.	
			break;  
		case "error":  
			rc = false;
			break;         
  		default:  
			rc = true;
			break;  
    }  
	return rc;
}

function smartobject_file_ext(layer) {  
    try {         
        var r = new ActionReference();     
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("smartObject"));  
        r.putIdentifier(stringIDToTypeID("layer"), layer.id);  
        var name = executeActionGet(r).getObjectValue(stringIDToTypeID("smartObject")).getString(stringIDToTypeID("fileReference"));         
         
        var n = name.lastIndexOf(".");  
        if (n < 0) return "";  
     
        return name.substr(n+1).toLowerCase();  
        }  
    catch (e) { return "error"; }  
}   

 

JJMack

Likes

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
Reply
Loading...
Nov 02, 2019 2
Adobe Community Professional ,
Nov 03, 2019

Copy link to clipboard

Copied

Thank you JJMack, that is a really useful post, more than what I was hoping for from the start, kudos!

Likes

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
Reply
Loading...
Nov 03, 2019 0
Most Valuable Participant ,
Nov 03, 2019

Copy link to clipboard

Copied

Once opened there are still problem you need to address in the edit code smart objects file types differ and features like Place should be avoided because of the strange things the Photoshop Place feature does. You can use place if you know how place works most users do not the have it wrong as to how place works it resizes because of different resolutions and may also scale the created smart object. You need to know how to deal with Place's operation.

 

 Then you need to flatten the document if the object type is a jpeg object for you need to use a save to save the work file save as will not do that.  Save will fail if there are layers.

JJMack

Likes

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
Reply
Loading...
Nov 03, 2019 0
Most Valuable Participant ,
Nov 03, 2019

Copy link to clipboard

Copied

Here is a function I wrote that edits a Photoshop smart object layer's Object in Photoshop.  This is not a complete script it is a function used  in  my Batch Mockup Scripts that is in the package I posted. Note it uses Open Copy Paste not Place so a third document is opened.  The Document is used to resize the replacement content and which is then pasted into the  smart object temp work document.  That Document is closed and the temp work document is closed with save and close.  Photoshop then updates the smart object layer in the document that was active when the script function was used. With my Batch Mockup scripts that document would be a Mockup template that script opened to be batch populated. The function is pass the replacement file, the smart object layer the has a Photoshop object, and two edit options Boolean, rotate for best fit and fit image. The function open both the Object and the replacement content file. Note all the Try Catch statement I needed to use to gets the function to work well. I needed 6 of them. The function may run into a Photoshop problem and raise an alert message and when  the message is dismissed the script will continue to process the batch without updating that layers smart object layer. So far I have not see this happen. If it does there is a possibility of documents opened in the function  being left open in Photoshop. It not always easy to program around software and file problems .

 

 

 

 

 

 

 

 

function editContents(newFile, theSO, rotateForBestFit, fitImage) {    
    try {    
		var lyrVis = theSO.visible; 
        app.activeDocument.activeLayer = theSO;  
		var smartObject = openSmartObject (theSO);			// open smart object;
		smartObject.flatten();	
		smartObject.activeLayer.isBackgroundLayer=0;		// Make it a normal Layer
		smartObject.selection.selectAll();
		smartObject.selection.clear();						// Clear
		var objWidth=smartObject.width.value;
		var objHeight=smartObject.height.value;	   
		open(File(newFile));								// open into a document	
		var layers = activeDocument.layers;
		activeDocument.activeLayer = layers[layers.length-1]; // Target Bottom Layer
		activeDocument.activeLayer.isBackgroundLayer=0; 	// Make it a normal Layer		
		try {
			var objFile= app.activeDocument;				// image document
			if (rotateForBestFit) {
				if (objFile.width.value<objFile.height.value&&objWidth>objHeight ) { objFile.rotateCanvas(-90.0);  } // Rotate portraits
				if (objFile.height.value<objFile.width.value&&objHeight>objWidth ) { objFile.rotateCanvas(-90.0);  } // Rotate landscapes
				}
			if (!fitImage) {		
				if (objFile.width.value/objFile.height.value > objWidth/objHeight) { objFile.resizeImage(null, objHeight, null, ResampleMethod.BICUBIC); } // wider
				else {objFile.resizeImage(objWidth, null, null, ResampleMethod.BICUBIC);} // same aspect ratio or taller
			}
			else{
				if (objFile.width.value/objFile.height.value > objWidth/objHeight) {objFile.resizeImage(objWidth, null, null, ResampleMethod.BICUBIC);  }  // wider
				else {objFile.resizeImage(null, objHeight, null, ResampleMethod.BICUBIC);}
			}
			try {objFile.resizeCanvas(objWidth, objHeight, AnchorPosition.MIDDLECENTER);}	
			catch(e){}
			try{
				mrkLayer = objFile.artLayers.add();				// Add a Layer
				mrkLayer.name = "TL BR Stamp";					// Name Layer
				mrkLayer.blendMode = BlendMode.OVERLAY;			// blend mode
			}
			catch(e){}
			mrkColor = new SolidColor;						
			mrkColor.rgb.red = 128;
			mrkColor.rgb.green = 128;
			mrkColor.rgb.blue = 128;
			try{
				var selectedRegion = Array(Array(0,0), Array(1,0), Array(1,1), Array(0,1));  // Top Right
				objFile.selection.select(selectedRegion);		
				objFile.selection.fill(mrkColor);
				var selectedRegion = Array(Array(objWidth-1,objHeight-1), Array(objWidth,objHeight-1), Array(objWidth,objHeight), Array(objWidth-1,objHeight)); // Bottom Right
				objFile.selection.select(selectedRegion);		
				objFile.selection.fill(mrkColor);	
			}
			catch(e){}
			objFile.selection.selectAll();
			try {objFile.selection.copy(true); }			//copy merge resized image into clipboard
			catch(e){objFile.selection.copy(); }			//copy resized image into clipboard
			objFile.close(SaveOptions.DONOTSAVECHANGES);	//close image without saving changes		
			smartObject.paste();							//paste change smart object content from being empty
		}
		catch(e) { objFile.close(SaveOptions.DONOTSAVECHANGES); } // close image without saving changes smart object is empty though
		if (smartObject.name.indexOf(".jpg")!=-1) smartObject.flatten();	
		smartObject.close(SaveOptions.SAVECHANGES);	//close and save
		theSO.visible =	lyrVis; 
        return app.activeDocument.activeLayer    
    }     
    catch(e) { alert(e); }    
}     	

 

 

 

 

 

 

The inner function to open the object function uses Action manager code  not your run menu item DOM code. In my Scripts this should work for the object has been tested to be a Photshop supported object. If the function fails to open the object the try catch in edit content function will catch this. So far this has not happened.  If it does happen that smart object layers object will not be updated and the usere will see the alert message that a error happened with the layers object. The function returns the open work document when open object works.

 

 

 

 

 

 

////// open smart object //////
function openSmartObject (theLayer) {
	if (theLayer.kind == "LayerKind.SMARTOBJECT") {
		// =======================================================
		var idplacedLayerEditContents = stringIDToTypeID( "placedLayerEditContents" );
			var desc2 = new ActionDescriptor();
		executeAction( idplacedLayerEditContents, desc2, DialogModes.NO );
	};
	return app.activeDocument
};

 

 

 

 

 

 

JJMack

Likes

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
Reply
Loading...
Nov 03, 2019 0
Engaged ,
Mar 11, 2020

Copy link to clipboard

Copied

Thanks for posting this update! Definitely helps to have the other function to be able to detect. As per usual PS scripts are an enigma, even with the script listener plugin.

Likes

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
Reply
Loading...
Mar 11, 2020 0
Engaged ,
Jan 01, 2021

Copy link to clipboard

Copied

@JJMack Hi there,

 

ive used part of a different script and altered it. It has the same idea, which is to open an smarotbject plane a new image save the temp file, close and export a JPG. I had it working at a certain point, but stuppidly i didnt make a backup copy of that one. I kept optimizing it but suddenly it would run properly. I keeps placing the image in the main document. The issue is that Photoshops GUI doesnt seem to update properly before the placement code is run. I tried adding sleep, app.refresh and wait commands, but non of them help. I also tried part of you edit object code but it returns an error. Somehow the code runs before the smartobject is opened. On OSX it did run nice at one point, that was CC2018 at home i run a newer version, 2021, but i find that version kind of slaggish. The GUI isnt responding very smooth on Windows. For instance when i have 2 docs open and close one, its litteraly takes seconds before the GUI updates and show the layers of the other document. I think this GUI delay is also causing this script to fail

 

here's my test version, its a but sloppy with all those commented parts, i like to switch functions while im testing so i keep them in. When it runs i always clean it up.

 

I only get it to work when i add an alert function after the edit placed content. It seems only then does the GUI update properly. I think i could add a function which stores the main files name and path then close it and open the smartobject, but it will lose the link then i guess.

 

Do you have an idea perhaps?

// Save JPOG from placed smartbojects
// https://community.adobe.com/t5/photoshop/smart-object-automation-script/td-p/8877231?page=1

#target photoshop

// Get OS
// fromt "_LastLogEntry.jsx"
isWindows = function() {
  return $.os.match(/windows/i);
};
isMac = function() {
  return !isWindows();
};
var osPath = (isMac() ? '/' : "/"); // resolve windows vs osx paths
// alert(isMac())

function exportMockupDesigns (){
    if (app.documents.length > 0) {
        var docRef = app.activeDocument;
        var docName = docRef.name.match(/(.*)\.[^\.]+$/)[1];
        var docPath = docRef.path;
        var actLayer = docRef.activeLayer;
        // jpg options;
        var jpgopts = new JPEGSaveOptions();
        jpgopts.embedProfile = true;
        jpgopts.formatOptions = FormatOptions.STANDARDBASELINE;
        jpgopts.matte = MatteType.NONE;
        jpgopts.quality = 8;
        // check if layer is smart object;
        if (actLayer.kind != "LayerKind.SMARTOBJECT") {
            alert("selected layer is not a smart object")
        } else {
            // select files;
            if ($.os.search(/windows/i) != -1) {
                var theFiles = File.openDialog("please select files", "*.psd;*.tif;*.jpg;*.jpeg;", true)
            } else {
                var theFiles = File.openDialog("please select files", getFiles, true)
            };
            if (theFiles) {
                 var destinationFolder = Folder.selectDialog("Please select a destination folder");
                // work through the array;
                for (var m = 0; m < theFiles.length; m++) {
                    // var edit = editSmOB();
                    var edit = openSmartObject (actLayer)
                    //alert(edit)
                    if(edit) {
                        var place = placeImage(theFiles[m])
                        //alert(place)
                        saveTmpDoc()
                    }
                    if(place){
                        var theNewName = theFiles[m].name.match(/(.*)\.[^\.]+$/)[1];
                        // alert(theNewName)
                        //save jpg;
                        docRef.saveAs((new File(destinationFolder.toString() + "/" + docName + "_" + theNewName + ".jpg")), jpgopts, true);

                    }
                    // var theNewName = theFiles[m].name.match(/(.*)\.[^\.]+$/)[1];
                    //save jpg;
                    // docRef.saveAs((new File(docPath + "/" + docName + "_" + theNewName + ".jpg")), jpgopts, true);

                }
            }
        }
    }

    


    ////// get psds, tifs and jpgs from files //////
    function getFiles(theFile) {
        if (theFile.name.match(/\.(psd|tif|png|jpg|jpeg)$/i) != null || theFile.constructor.name == "Folder") {
            return true
        };
    };
    


    function cTID(s) { return app.charIDToTypeID(s); };
    function sTID(s) { return app.stringIDToTypeID(s); };


    function waitMoment(){
        var eventWait = charIDToTypeID("Wait")        
        var enumRedrawComplete = charIDToTypeID("RdCm")
        var typeState = charIDToTypeID("Stte")
        var keyState = charIDToTypeID("Stte")
        var desc = new ActionDescriptor()
        desc.putEnumerated(keyState, typeState, enumRedrawComplete)
        executeAction(eventWait, desc, DialogModes.NO)
    }

    function editSmOB() {
        app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
        waitMoment();
        return true            
        // var desc110 = new ActionDescriptor();
        // executeAction( sTID('placedLayerEditContents'), desc110, DialogModes.NO );
        // waitMoment()
        
    }

    function openSmartObject (theLayer) {
        current = app.activeDocument;
        if (theLayer.kind == "LayerKind.SMARTOBJECT") {
            runMenuItem(stringIDToTypeID('placedLayerEditContents'));
            waitMoment();
            // if ( current == app.activeDocument) {
            //     try {         
            //         var r = new ActionReference();     
            //         r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("smartObject"));  
            //         r.putIdentifier(stringIDToTypeID("layer"), theLayer.id);  
            //         var name = executeActionGet(r).getObjectValue(stringIDToTypeID("smartObject")).getString(stringIDToTypeID("fileReference"));   
            //         waitMoment();      
            //         }  
            //     catch (e) { 
            //         // throw theLayer + " Smart Object Did not Open"; }  
            //         alert(theLayer + " Smart Object Did not Open");
            //          }  
            //     var workFile = new File(Folder.temp + "/" +  name);  // May work for both Windows and Mac
            //     //alert(workFile)
            //     app.open(File(workFile));
            //     // if (workFile.exists) app.open(File(workFile));
            //     // if ( current == app.activeDocument) alert( theLayer + " Smart Object Did not Open");
            // }
        }
        return app.activeDocument
    };

    // Edit smartobject
    function editSmartObject(newLinkedFile){
        var idplacedLayerEditContents = stringIDToTypeID( "placedLayerEditContents" );
        var edtSmaObj = new ActionDescriptor();
        executeAction( idplacedLayerEditContents, edtSmaObj, DialogModes.NO );
        

        var desc224 = new ActionDescriptor();
    //     desc224.putPath( cTID('In  '), new File( "/private/var/folders/l0/wnzt19xd0tvgqwmljhfq_4rc0000gn/T/TemporaryItems/Rectangle 2.psb" ) );
        desc224.putPath( cTID('In  '), new File( "C:/Users/romboutversluijs/AppData/Local/Temp/Rounded Rectangle 1.psb" ) );
        desc224.putInteger( cTID('DocI'), 587 );
        desc224.putEnumerated( sTID('saveStage'), sTID('saveStageType'), sTID('saveSucceeded') );
        executeAction( cTID('save'), desc224, DialogModes.NO );

        
    };


    //  scale to from Scale to fit > dont know resource
    //
    function rectangle(x, y, width, height) {
        return { x:x, y:y, width:width, height:height };
    }

    //  Get layerbounds
    //  https://graphicdesign.stackexchange.com/questions/21162/photoshop-action-to-determine-dimensions-of-layer
    function layerBounds(){
        // alert(activeDocument)
        var layer = activeDocument.activeLayer; //Grab the currently selected layer
        //Calculate length and width based on the rectangular bounds of the selected layer
        var width = Number(layer.bounds[2]-layer.bounds[0]); //Grab the width
        var height = Number(layer.bounds[3]-layer.bounds[1]); //Grab the height
        
        return [width, height]
    }

    //  Place image
    function placeImage(newFile) {
        // Switch document
        // var desc111 = new ActionDescriptor();
        //     var ref13 = new ActionReference();
        //     ref13.putOffset( cTID('Dcmn'), 1 );
        // desc111.putReference( cTID('null'), ref13 );
        // desc111.putInteger( cTID('DocI'), 344 );
        // executeAction( cTID('slct'), desc111, DialogModes.NO );


        // waitMoment()
        // alert(newFile)
        var desc174 = new ActionDescriptor();
        desc174.putInteger( cTID('Idnt'), 885 );
        desc174.putPath( cTID('null'), new File(newFile));
        // desc174.putPath( cTID('null'), new File( "/Volumes/_MINDFLOW/_MINDFLOW/CLIENTS/Allusion/Export/Mockups/Rombout-Mockup-01-v8/Mockuo-08-GRID-Tags-Drk.jpg" ) );
        desc174.putBoolean( cTID('Lnkd'), true );
        desc174.putEnumerated( cTID('FTcs'), cTID('QCSt'), cTID('Qcsa') );
            var desc175 = new ActionDescriptor();
            desc175.putUnitDouble( cTID('Hrzn'), cTID('#Pxl'), 0.000000 );
            desc175.putUnitDouble( cTID('Vrtc'), cTID('#Pxl'), 0.000000 );
        desc174.putObject( cTID('Ofst'), cTID('Ofst'), desc175 );
        desc174.putUnitDouble( cTID('Wdth'), cTID('#Prc'), 234.782609 );
        desc174.putUnitDouble( cTID('Hght'), cTID('#Prc'), 234.697509 );
        executeAction( cTID('Plc '), desc174, DialogModes.NO );
        
        var tmpDoc = app.activeDocument;
        // $.sleep (5000);
        
        // var tmpDoc = app.activeDocument;
        // alert(tmpDoc.name)
        // var tmpDocWidth = new UnitValue (tmpDoc.width);
        // var tmpDocHeight = new UnitValue (tmpDoc.height);

        // alert(newFile)
        // var desc174 = new ActionDescriptor();
        // desc174.putInteger( cTID('Idnt'), 885 );
        // desc174.putPath( cTID('null'), new File(newFile));
        // // desc174.putPath( cTID('null'), new File( "/Volumes/_MINDFLOW/_MINDFLOW/CLIENTS/Allusion/Export/Mockups/Rombout-Mockup-01-v8/Mockuo-08-GRID-Tags-Drk.jpg" ) );
        // desc174.putBoolean( cTID('Lnkd'), true );
        // desc174.putEnumerated( cTID('FTcs'), cTID('QCSt'), cTID('Qcsa') );
        //     var desc175 = new ActionDescriptor();
        //     desc175.putUnitDouble( cTID('Hrzn'), cTID('#Pxl'), 0.000000 );
        //     desc175.putUnitDouble( cTID('Vrtc'), cTID('#Pxl'), 0.000000 );
        // desc174.putObject( cTID('Ofst'), cTID('Ofst'), desc175 );
        // desc174.putUnitDouble( cTID('Wdth'), cTID('#Prc'), 234.782609 );
        // desc174.putUnitDouble( cTID('Hght'), cTID('#Prc'), 234.697509 );
        // executeAction( cTID('Plc '), desc174, DialogModes.NO );
        
        // var tmpDoc = app.activeDocument;
        // alert(tmpDoc.name)
        // return tmpDoc
        return true
        // transLayer(layerBounds(),tmpDocWidth,tmpDoc);
        
    };


    //  Transform layer
    //  ScriptListener
    function transLayer(layerbounds,tmpDocWidth,tmpDoc) {    
        var scale = ((Number(tmpDocWidth) / layerBounds()[0]) * 100);
        
        var trnsLayer = new ActionDescriptor();
        trnsLayer.putEnumerated( cTID('FTcs'), cTID('QCSt'), cTID('Qcsa') );
            var adLayer = new ActionDescriptor();
            adLayer.putUnitDouble( cTID('Hrzn'), cTID('#Pxl'), -0.000000 );
            adLayer.putUnitDouble( cTID('Vrtc'), cTID('#Pxl'), 0.000000 );
        trnsLayer.putObject( cTID('Ofst'), cTID('Ofst'), adLayer );
        trnsLayer.putUnitDouble( cTID('Wdth'), cTID('#Prc'), scale);
        trnsLayer.putUnitDouble( cTID('Hght'), cTID('#Prc'), scale);
        executeAction( cTID('Trnf'), trnsLayer, DialogModes.NO );
        

        // alert(saveTmpDoc(tmpDoc))
        if(saveTmpDoc(tmpDoc)){
            closeSmartOjbectDoc(); // close tempdoc
        } // save tempdoc

    };

    // Origial save code
    // function ftn15() {
    //   function cTID(s) { return app.charIDToTypeID(s); };
    //   function sTID(s) { return app.stringIDToTypeID(s); };

    //     var desc224 = new ActionDescriptor();
    //     desc224.putPath( cTID('In  '), new File( "/private/var/folders/l0/wnzt19xd0tvgqwmljhfq_4rc0000gn/T/TemporaryItems/Rectangle 2.psb" ) );
    //     desc224.putPath( cTID('In  '), new File( ""C:\Users\romboutversluijs\AppData\Local\Temp\Rounded Rectangle 2.psb"" ) );
    //     desc224.putInteger( cTID('DocI'), 587 );
    //     desc224.putEnumerated( sTID('saveStage'), sTID('saveStageType'), sTID('saveSucceeded') );
    //     executeAction( cTID('save'), desc224, DialogModes.NO );
    // };

    function saveTmpDoc() {
        // alert(tmpDoc)
        var tmpDoc = app.activeDocument
        var tmpPath = tmpDoc.path;
        var tmpSave = tmpPath + osPath + tmpDoc.name; //tmpDoc + '/' + tmpDoc.name;
        
        alert(osPath)
        alert(tmpSave)
        var saveTmp = new ActionDescriptor();
        saveTmp.putPath( cTID('In  '), new File( tmpSave ) );
        saveTmp.putInteger( cTID('DocI'), 587 );
        saveTmp.putEnumerated( sTID('saveStage'), sTID('saveStageType'), sTID('saveSucceeded') );
        executeAction( cTID('save'), saveTmp, DialogModes.NO );


        return true

    };



    // Close document smart object
    function closeSmartOjbectDoc() {
        var clsSmaObjDoc = new ActionDescriptor();
        clsSmaObjDoc.putInteger( cTID('DocI'), 587 );
        clsSmaObjDoc.putBoolean( sTID('forceNotify'), true );
        executeAction( cTID('Cls '), clsSmaObjDoc, DialogModes.NO );
        return true
    };
}

//  Suspend History
//  Better for memory, doesnt clutter history when doing a lot automation
// exportMockupDesigns.main = function() {
//     exportMockupDesigns();
// };

// app.activeDocument.suspendHistory("Script > Export Mockup Designs", 'exportMockupDesigns.main()');
exportMockupDesigns();

 

 

Likes

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
Reply
Loading...
Jan 01, 2021 0
Most Valuable Participant ,
Jan 01, 2021

Copy link to clipboard

Copied

I have no desire to look at your code. If you are  using Photoshop Place you need to understand hop Photoshop Place feature works. Its implementation is very strange, and it will scale the replacement  object if the two documents resolution are not the same and also scale the layer to fit on canvas if the object layer created scaled  to a layer that is larger than canvas. In my mockup scripts Edit object function I do not use Photoshop Place I Open replacement and  use copy and paste. So at some point the are three Document open in Photoshop. The Mockup Template, The Smart Object Work document and the Replacement image document.  After I use copy in the replacement image document I close the replacement document and paste the resize image into the Objects Work document then save and closet the the Object work Document so Photoshop will update the Templates document smart object layer. 

 

It may be that the Object work file may not be opening in your case because of how the template Smart object works.  So Place placed the replacement into your template not  your object.  I had to change  my code a few weeks ago because of that.  Someone Posted a Template that had a Smart Object that did not Open in  Photoshop when Open smart object is used on the template's smart object layer. It Also did not throw are error sof my script destroyed the template..  Using the script listener on that template I saw the Photoshop did create the temp work file but added an Open  after  the  Open smart object  smart to open the object work file.  I had to add code to text if  the  open Smart Object opened  the work file into a photoshop document and if not open  use file open to open the work file Photoshop created but failed to open.

 

The code I posted for you hads a  function that opened the smar object that I had to update to insure the work document opens. here is that code.

////// open smart object //////
function openSmartObject (theLayer) {
	current = app.activeDocument;
	if (theLayer.kind == "LayerKind.SMARTOBJECT") {
		runMenuItem(stringIDToTypeID('placedLayerEditContents'));
		if ( current == app.activeDocument) {
			try {         
				var r = new ActionReference();     
				r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("smartObject"));  
				r.putIdentifier(stringIDToTypeID("layer"), theLayer.id);  
				var name = executeActionGet(r).getObjectValue(stringIDToTypeID("smartObject")).getString(stringIDToTypeID("fileReference"));         
				}  
			catch (e) { throw theLayer + " Smart Object Did not Open"; }  
			var workFile = new File(Folder.temp + "/" +  name);  // May work for both Windows and Mac
			if (workFile.exists) app.open(File(workFile));
			if ( current == app.activeDocument) throw theLayer + " Smart Object Did not Open";
		}
	}
	return app.activeDocument
};

 

JJMack

Likes

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
Reply
Loading...
Jan 01, 2021 1
Engaged ,
Jan 01, 2021

Copy link to clipboard

Copied

Thanks, for the semi reply.

 

I know how most of it works, the issue is not related to what your explaining though. My issue is that i run an edit command and then after that it should place an image into that smartobject file. I already know the scale so i added that to the place command. Im thinking of either making a dialog for that. But i also got a function which get the bounds of the document i then get the bound of the placed file, with those two i can figure out the proper scaling i need.

 

The issue is that photoshop runs all the code before that smartobject is actually opened. I need photoshop to wait until that document is open. I feels like its running asynchronous, if i named it correct. Its running multiple actions before 1 is finished.

here's an image from a Medium article as an example and to clearify what i think is happening
example synchronous vs asynchronousexample synchronous vs asynchronous

 

My work around for now is have that smartobject open already, then i simply use a switch command and save in between. This works, i let it run a couple times and each time i got the proper exports.

 

Im just going insane of why i had it working at one point andcant seem to replicate that code. I used scriptlistener and scriptfix to get most parts i need to edit the files. Than added some extras for functionality.

Likes

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
Reply
Loading...
Jan 01, 2021 0
Most Valuable Participant ,
Jan 01, 2021

Copy link to clipboard

Copied

Two point  I just tried to a made were.

 

Place implementation is strange.  Place may well scale the smart object image.  You can not get the object size for sure using the layers bounds unless you first scale the layer to 100%. If may have been scaled to fit on canvas.  Resized to 100% may also get a size different than the actual image because resolutions did not match and the replacement image was scaled.  You can resize that scaled object 100% size to fill the object size.

 

If you feel the document did not open on time it may be it will not open.  Like the Problem I had with the smart object in the template someone posted. My script destroyed the template because it did not open. The Active Document remained the template document. The Smart Object's  Temp Work file did not open with Photoshop menu item "placeLayerEditContents" and there was no error  I had to add code to test to see if the Active document remained the template document after the "placeLayerEditContents"  command and if it was I had to  add command to actually open the temp work file created by the "placeLayerEditContents"  command that failed to open Like Photoshop did when I manually used "placeLayerEditContents"  from Photoshop UI.  That is what was added into the code I just posted.   I have only seen that problem with the Smart Object Layer in the Template some posted and said they had a problem  opening the smart object layer in a script.   I tried in vain toe create an othe smat Object Layer the would fail to open with "placeLayerEditContents" but never found the way that smart object layer was created.

 

If you are using a Mac  there may be a problem in Photoshop or mac OS where things did not interlock correctly. If  "placeLayerEditContents"  opens your smart object Photoshop should switch document completely before the next script command executes. I have only seen an interlock problem like that on windows with Photoshop CS6 when it was first released Photoshop version 13.0  

 

JJMack

Likes

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
Reply
Loading...
Jan 01, 2021 1
Most Valuable Participant ,
Jan 02, 2021

Copy link to clipboard

Copied

I took a quick look at your code and see two problems.   First I see no code that test what kind of object is in template's smart object layer.  That is a big problem.  Not all Smart Objects are Photoshop Objects.  None Photoshop Objects will not be opened by Photoshop.  For example Vector Smart Objects will open in  AI or whatever applications open Vector image files by default. Camera RAW file will open in ACR interactive UI.

 

My scripts test Smart Object Layer object type and will bypass opening smart object layers that contain none Photoshop objects.  If  template has a smart object that is not a Photoshop object the open smart object function will not open those object in Photoshop.  The pause you add where you comments out my fix for object that should open in Photoshop but fail to open.  I test to see if placeLayerEditContent  created the temp work file. If the file exist I open the work document.     If the object work document does not exista or open then my open smart object  function throws an error which is caught by my EditSmarObject function.  You commented that code out of the Open Smart Object function your function does not throw an error when the object does not open in Photoshop.

 

Your script will fail to work correct when ever a Smart Object fails to open in Photoshop.  If a template has  a smart object layer the has Vector or RAW object your script will fail.

 

If your Smart Object is a Photoshop Object my code you commented out is design to open the temp Work  File created by Photoshop containing the objects content but did not open in Photoshop.  I have only seen that happen for one smart object in a template some posted here. 

 

You are not createing a CEP extension that can multi task.  In you script Photoshop steps should execute in sequencs.  If you use placeLayerEditContent  on as smart object layer that object the will open in photoshop that step is not complete till the document open in Photoshop.  If the Object will open in AI  the placeLayerEditContent step is complete once Photoshop passes the temp work file to your system to open. The file will open is some other application or fail to be open if there is no assocated application.  So you will not be able to work on the object to update the smart objects content if its not open in Photoshop..

JJMack

Likes

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
Reply
Loading...
Jan 02, 2021 1
Engaged ,
Jan 02, 2021

Copy link to clipboard

Copied

@JJMack 

 

thanks again for trying to explain your approach. I dont have problems with the placing, my files are smaller than in resolutuion when placed, thats why get doc bounds works in this case.

 

I also noticed that when using scriptlistner, photoshop actually runs another command after the editplaced. I was thinking of doing that but didnt know a method how to get the proper temp dir. I saw your implementation and that is quite nice. However when using it still runs code before the document is actually open. The edut command is given and i return a true state, only when its try should it do the rest of the steps. But it receives true and does the placement of files but still on the main doc. After the script has run or is near the end, only then is that smartobject opened. I found a different script which saves all placed smartobjects, that also uses editplaced and then when its open it saves it as a psd.

I will check that one and try to understand why the save command does run in the correct order. In that version it saves the opened smartobject after its opened. It runs a save command after the editplaced. Im not sure why in my case the place command keeps running before the smartobject is actually opened.

 

Using you version it keeps returning cant open the doc. But that is false, it does open but it looks like the ui is slower or so. That why i showed that synchronous vs asynchronous image. I have the feeling its running more functions almost at the same time. I returns true but the document is not yet open at that point. I got a workaround working which opens the smartobject before we run the script. I then switch back and forth between the 2 docs, that works but isnt as clean as i would want it to be

Likes

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
Reply
Loading...
Jan 02, 2021 0
Most Valuable Participant ,
Jan 03, 2021

Copy link to clipboard

Copied

The thing is Photoshop commands should be synchronous not be run in separate task  asynchronously that would requite a script or action to synchronize processing that needs to be done in sequence.   I saw problem in CS6  Photoshop version 13.0 where Photoshop operating was not  synchronize that cause Script and actions that process multiple document would fail sometimes because the was no active  document where the step executed the required a active document Photoshop had bot finished switching documents so the steps would fails for they were not available for execution there was no Active Document. 

 

You noticed that when using scriptlistner, photoshop actually runs another command after the editplaced. I only saw that happen for the Smart Object Layer in one template someone posted in a thread in this forum.   All of my template  object opened with editplaced without and additional command.   The addition command I saw the scriptlistener record for the one template object was an open for the temp work file Photoshop created for the object.   So I added that open to my open smart object function if the was no document switch.   The code I add works on a Window PC I think it should work on a Mac.  However it may not work if the Object is a vector or raw object  Photoshop doesx]x not directly support Camera RAW file and Vector Image Files.    My mockup script test smart object  layer object type it they contain a RAW or Vector object my script will display a message that object is nit supported and  bypass editing those templates smart object layers.    The Code I added to Open Smart Object test to see if Photoshop has switched documents.  If the document switch did not occur I try to open the work document that editplaced should have created if the work file exists. I again test if the document switch happens. if not I fail with smart object did mot open..

 

If you feel your problem is opening the object is just taking long time you should change your waitMoment() function to wait for the document switch to happen.   However, I feel your problem is more likely that you object is either a not Photoshop object its a RAW or Vector File or the open work file the extra command is needed.

 

JJMack

Likes

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
Reply
Loading...
Jan 03, 2021 0
Engaged ,
Jan 03, 2021

Copy link to clipboard

Copied

@JJMack 

 

thanks again JJMack for trying to help, much appreciated. The smartobject layer is a layer converted to smartobject, it has no physical link or path. Its is a PSB file which is the default Photoshop uses when converting layers into smartobjects. All the code ive added is from scriptlistner and is placed one after the other. The check you added seems to be failing in my case because the script is faster than the GUI of photoshop. 

I also tried adding app.refresh, wait and sleep. None of these seem to help to update the GUI and show the opening of the smartobject before the script continuous. Using your functions from your template files kept returning an error. I find this strange, i mean i know what file the smartobject is, i even did extra check to make sure irs either PSD or PSB, it also shows its a PSB in the properties panel.

 

What i find strange is that in the other script i found, which has about the same base of looping over layers and then use a editplacedcontent and then save as PSD does run just fine. I dont see the GUI change that much, but it saves all files properly. Could it be the place linked cant be used properly in this instance?

 

Your template file opens and closes all the files, is that correct? Perhaps that is the only case possible here, but im not very fond of that because you loose time because it needs to open and read documents each time.

 

I will try again and see if i can add the waiting at a different location in the script. Ive tried so many locations and still have not found the correct approach.

 

PS im testing on both Windows and OSX, the difference is that Windows is 2021 and OSX 2018. I do notice that the Windows version act really strange. Each time i close a document it looks like the GUI is freezing, for 1-2 seconds i keep seeing all the layer from and already closed document. Perhaps its my system but that would be weird. I mean this is a brand new AMD Ryzen 7 machine. I did do some googling on this 2021 version and found quite some posts about people stating its lagging. Perhaps thats causing the issue. What lots of people state is what im experiencing as well, i believe. The GUI feels like its freezing up 1-2 seconds or so 

Likes

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
Reply
Loading...
Jan 03, 2021 0
Most Valuable Participant ,
Jan 03, 2021

Copy link to clipboard

Copied

Please post  one of your templates you are having issues with.  It would like to see if I can make it compatible with my scripts so I can test it with my mockup scripts on windows.  I'm not having problems on my machine its old and slow. It just meets PS 2GHZ requirement  PS is not good using two processor and multitasking. My old dell workstation has two 6 core 2 GHz xeons.

 

Please upload a template and post a link to it.

 

I have many version of Windows PS installed.  PS 2021 has issues but My Scripts seem to work fine with 2021 ver 22.1

JJMack

Likes

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
Reply
Loading...
Jan 03, 2021 0
Most Valuable Participant ,
Jan 03, 2021

Copy link to clipboard

Copied

Something strange is going on.   I made a change to my Open Smart Object  where I was adding the open step that worked for me.  I put out an alert before adding the open.  If knew I would get the message on the first open of the smart object  but not the rest off the opens for the object in the batch the object opens  with the editobject command.  I waited a long time before dismissing the alert.  Low and behold the object temp work document opened before I added the open command.  When I dismissed the alert the Open I added fails because it was open.  

 

So tried change the function to wait for the editobject to eventualy switch document.  Without putting out the  pausing alert.   I tried

 

while ( current == app.activeDocument) app.refresh();

 

The work file document never opened

 

With the pause alert and waiting it does open and Photoshop swatches the document for the script.

This worked it tool a long time for the object to open adding the open performed better.

 

////// open smart object //////
function openSmartObject (theLayer) {
	current = app.activeDocument;
	if (theLayer.kind == "LayerKind.SMARTOBJECT") {
		runMenuItem(stringIDToTypeID('placedLayerEditContents'));
		if( current == app.activeDocument) {
			alert("pause");
			if( current != app.activeDocument) return app.activeDocument;
			alert("Adding open step");
			
			try {         
				var r = new ActionReference();     
				r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("smartObject"));  
				r.putIdentifier(stringIDToTypeID("layer"), theLayer.id);  
				var name = executeActionGet(r).getObjectValue(stringIDToTypeID("smartObject")).getString(stringIDToTypeID("fileReference"));         
				}  
			catch (e) { throw theLayer + " Smart Object Did not Open"; }  
			var workFile = new File(Folder.temp + "/" +  name);  // May work for both Windows and Mac
			if (workFile.exists) app.open(File(workFile));
			if ( current == app.activeDocument) throw theLayer + " Smart Object Did not Open";
		}
	}
	return app.activeDocument;
};

 

 

JJMack

Likes

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
Reply
Loading...
Jan 03, 2021 0
Engaged ,
Jan 03, 2021

Copy link to clipboard

Copied

@JJMack 

 

thanks once more for taking the time to look at it. I also had the same idea what you did with the while loop, but its goes into never ending loop. The script simply runs to fast for the GUI to even do anything. I tried a couple variations like if doc lenght isnt 2 then rerun the same function. That also goes into this never ending loop and i need to escape running script and in some cases even need force end photoshop because i cant get the script to stop.

 

PS i forgot to mention it earlier, your open smartobject function also throws this error. There i something not correct in the code, perhaps its missing curly brackets. I do see these one line if states before and sometimes they work. However i think its "throw" which is causing this error. Is this perhaps because i use the extension JSX vs JS?!


this is the error i get when adding your open smartobject functionthis is the error i get when adding your open smartobject function

 

Ive started a fresh new file with some test code in there to check if the editcontent works. PS it will always work if you an alert in there, somehow when i use that the GUI does update properly. But running file without will not run the script properly.

 

In this current state, your function throws a script error which we see in the image above.

 

The way i run this is have the mockup, so the PSD with the phone. I select the layer which is red (smartobject). I run the script, it will prompt you to select images, For a test i made those screen image in that zip file. Select one or a couple. It will then prompt for an export folder. For now ive turned of the save function since the main function doesnt even run properly. 

#target photoshop


var docRef = app.activeDocument;
var actLayer = docRef.activeLayer;


function cTID(s) {
    return app.charIDToTypeID(s);
};

function sTID(s) {
    return app.stringIDToTypeID(s);
};




////// open smart object //////
function openSmartObject(theLayer) {
    current = app.activeDocument;
    alert(theLayer)
    if (theLayer.kind == "LayerKind.SMARTOBJECT") {
        runMenuItem(stringIDToTypeID('placedLayerEditContents'));
        if (current == app.activeDocument) {
            try {
                var r = new ActionReference();
                r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("smartObject"));
                r.putIdentifier(stringIDToTypeID("layer"), theLayer.id);
                var name = executeActionGet(r).getObjectValue(stringIDToTypeID("smartObject")).getString(stringIDToTypeID("fileReference"));
            } catch (e) {
                throw theLayer + " Smart Object Did not Open";
            }
            var workFile = new File(Folder.temp + "/" + name); // May work for both Windows and Mac
            if (workFile.exists) app.open(File(workFile));
            if (current == app.activeDocument) throw theLayer + " Smart Object Did not Open";
        }
    } else {
        alert(theLayer +" is not a smartobject");
    }
    return app.activeDocument
};



// Check if object is PS
// R-Bin - JJ Mack
// https://community.adobe.com/t5/photoshop/extendscript-photoshop-edit-contents-smart-layer/m-p/10706542#M273949
function objectIsPsObject(SOlayer) {
	//Thanks to r-bin
	var ext = smartobject_file_ext(SOlayer);  
    var rc = true;
	switch (ext)  
		{  
		case "nef":  
		case "cr3":  
		case "cr2":  		
		case "crw":  
		case "raf":  
		case "orf":  
		case "mrw":  
		case "dcr":  
		case "mos":  
		case "raw":  
		case "pef":  
		case "srf":  
		case "dng":  
		case "x3f":  
		case "erf":  
		case "sr2":  
		case "kdc":  
		case "mfw":  
		case "mef":  
		case "arw":  
		case "nrw":  
		case "rw2":  
		case "rwl":  
		case "iiq":  
		case "3fr":  
		case "fff":  
		case "srw":  
		case "ai":
		case "svg":
		case "pdf":
		case "esp":
			rc = false;	
			break;  
		case "error":  
			rc = false;
			break;         
  		default:  
			rc = true;
			break;  
    }  
	return rc;
}
  
function smartobject_file_ext(layer) {  
    try {         
        var r = new ActionReference();     
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("smartObject"));  
        r.putIdentifier(stringIDToTypeID("layer"), layer.id);  
        var name = executeActionGet(r).getObjectValue(stringIDToTypeID("smartObject")).getString(stringIDToTypeID("fileReference"));         
         
        var n = name.lastIndexOf(".");  
        if (n < 0) return "";  
     
        return name.substr(n+1).toLowerCase();  
        }  
    catch (e) { return "error"; }  
}    


function placeImage(newFile){
    // app.refresh(); // doesnt work
    // app.redraw();// doesnt work
    // waitMoment();
    // $.sleep(500)
    
    // Switch document
    // var desc111 = new ActionDescriptor();
    //     var ref13 = new ActionReference();
    //     ref13.putOffset( cTID('Dcmn'), 1 );
    // desc111.putReference( cTID('null'), ref13 );
    // desc111.putInteger( cTID('DocI'), 344 );
    // executeAction( cTID('slct'), desc111, DialogModes.NO );
    
    // Place images
    // alert(newFile)
    var desc174 = new ActionDescriptor();
    desc174.putInteger( cTID('Idnt'), 885 );
    desc174.putPath( cTID('null'), new File(newFile));
     desc174.putBoolean( cTID('Lnkd'), true );
    desc174.putEnumerated( cTID('FTcs'), cTID('QCSt'), cTID('Qcsa') );
        var desc175 = new ActionDescriptor();
        desc175.putUnitDouble( cTID('Hrzn'), cTID('#Pxl'), 0.000000 );
        desc175.putUnitDouble( cTID('Vrtc'), cTID('#Pxl'), 0.000000 );
    desc174.putObject( cTID('Ofst'), cTID('Ofst'), desc175 );
    desc174.putUnitDouble( cTID('Wdth'), cTID('#Prc'), 234.782609 ); // i know the scale > this will make the image fit the SO file
    desc174.putUnitDouble( cTID('Hght'), cTID('#Prc'), 234.697509 ); // i know the scale > this will make the image fit the SO file
    executeAction( cTID('Plc '), desc174, DialogModes.NO );

}
function exportMockupDesigns() {
    // Get OS
    // fromt "_LastLogEntry.jsx"
    isWindows = function() {
        return $.os.match(/windows/i);
    };
    isMac = function() {
        return !isWindows();
    };
    var osPath = (isMac() ? '/' : "/"); // resolve windows vs osx paths
    // alert(isMac())


    if (app.documents.length > 0) {
        var myDocument = app.activeDocument;
        var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
        var thePath = myDocument.path;
        var theLayer = myDocument.activeLayer;
        // jpg options;
        var jpgopts = new JPEGSaveOptions();
        jpgopts.embedProfile = true;
        jpgopts.formatOptions = FormatOptions.STANDARDBASELINE;
        jpgopts.matte = MatteType.NONE;
        jpgopts.quality = 8;
        // check if layer is smart object;
        if (theLayer.kind != "LayerKind.SMARTOBJECT") {
            alert("selected layer is not a smart object")
        } else if (objectIsPsObject(actLayer) != true) {
            alert("The SmartOjbect is not a PSB or PSD file")
            return 'cancel'; // quit, returning 'cancel' (dont localize) makes the actions palette not record our script
        } else {
            // select files;
            if ($.os.search(/windows/i) != -1) {
                var theFiles = File.openDialog("please select files", "*.psd;*.tif;*.jpg;*.jpeg;", true)
            } else {
                var theFiles = File.openDialog("please select files", getFiles, true)
            };
            // select Folder;
            // var theFolder = Folder.selectDialog("select folder");
            if (theFiles) {
                // var theFiles = theFolder.getFiles(/\.(jpg|tif|eps|psd|png)$/i);
                // Select destination folder
                var destinationFolder = Folder.selectDialog("Please select a destination folder");
                // work through the array;
                for (var m = 0; m < theFiles.length; m++) {
                    // replace smart object;
                    openSmartObject(theLayer);
                    // app.refresh()
                    // alert(editSO)
                    // waitMoment()
                    //  $.sleep(500)
                    // waitForRedraw();// notworking
                    placeImage(theFiles[m]);


                   // var theNewName = theFiles[m].name.match(/(.*)\.[^\.]+$/)[1];
                    //save jpg;
                   // myDocument.saveAs((new File(destinationFolder.toString() + "/" + theName + "_" + theNewName + ".jpg")), jpgopts, true);

                    // }
                }
            };
        }
    };

    ////// get psds, tifs and jpgs from files //////
    function getFiles(theFile) {
        if (theFile.name.match(/\.(psd|tif|png|jpg|jpeg)$/i) != null || theFile.constructor.name == "Folder") {
            return true
        };
    };
};
exportMockupDesigns();

 

 

Likes

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
Reply
Loading...
Jan 03, 2021 0
Engaged ,
Jan 03, 2021

Copy link to clipboard

Copied

This is the line causing that error 

 

 

if (current == app.activeDocument) throw theLayer + " Smart Object Did not Open";

 

 

 

Changing the file to .js vs .jsx doesnt help, it still returns that error. Its asif it doesnt understand throw statement.

 

On inspecting the throw error. I think your using it wrong, i you look at this example. Throw needs to be used with try and catch. Like you did a bit up in the function.

 

example how to use throwexample how to use throwYou used 2 different methods of throwYou used 2 different methods of throw

 

I dont think the try and catch make is very useful, its just adds more lines of code. Simply using if and then alert is about the same right?


i corrected the code and now the script does run. But it opens the wrong file.
corrected code with usage of throwcorrected code with usage of throw

 

Now with fuction working properly nothing is actually opened. As a check i added alert to see what layer is selected, however nothing is happening. I believe your function should alert if the smartobject cant be opened but it doesnt do that

////// open smart object //////
function openSmartObject(theLayer) {
    current = app.activeDocument;
    alert(theLayer)
    if (theLayer.kind == "LayerKind.SMARTOBJECT") {
        runMenuItem(stringIDToTypeID('placedLayerEditContents'));
        if (current == app.activeDocument) {
            try {
                var r = new ActionReference();
                r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("smartObject"));
                r.putIdentifier(stringIDToTypeID("layer"), theLayer.id);
                var name = executeActionGet(r).getObjectValue(stringIDToTypeID("smartObject")).getString(stringIDToTypeID("fileReference"));
            } catch (e) {
                throw theLayer + " Smart Object Did not Open";
            }
            var workFile = new File(Folder.temp + "/" + name); // May work for both Windows and Mac
            if (workFile.exists) app.open(File(workFile));
            try {
                if (current == app.activeDocument) {}
            } catch(e) {
                throw theLayer + " Smart Object Did not Open";
            }
        }
    } else {
        alert(theLayer +" is not a smartobject");
    }
    return app.activeDocument
};

  

Likes

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
Reply
Loading...
Jan 03, 2021 0
Engaged ,
Jan 03, 2021

Copy link to clipboard

Copied

Ow i see why its not working. Though the function should work it only works when the smartobject is openen alreadt otherwise that tempfile is not there and it passes resulting in nothing to happen. I check by forcing the file to be opened. Ill check what happen if i run the runMenuItem, ps shouldnt that be "app.runMenuItem", than add a wait or app.refresh then check if the file is there

 

force open the temp file, causes error because the file is not yet in the temp folder. The editplacecontent is failing to open itforce open the temp file, causes error because the file is not yet in the temp folder. The editplacecontent is failing to open it

 

Likes

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
Reply
Loading...
Jan 03, 2021 0
Engaged ,
Jan 03, 2021

Copy link to clipboard

Copied

Perhaps its just this photoshop version. I just noticed that using the button "Edit contents" in the properties panel actually doesnt do anything, thats kinda weird. The shortcut for it does work. That probably also why the runMenuItem doesnt do anything. Very strange, feels very buggy.

 

edit contents button not doing anythingedit contents button not doing anything

Then after closing and opening the file the button does work again, really strange behavior!

Likes

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
Reply
Loading...
Jan 03, 2021 0
Most Valuable Participant ,
Jan 03, 2021

Copy link to clipboard

Copied

Can you please post a PSD template you are having problem with.  I trying to find out what kind of objects do  not open with editobject synchronously.  So far the only template object that does not Open for me synchronous with editobject in my open smart object function is in a template  "Wall Interiors.psd" someone posted in this forum.  The Temp work file created  by Photoshop for editObject is a PSB file that has two layers. The top layer is a vector smart object layer an AI file the layer has a layer style the color overlay effect. Basically ii is an AI text layer with a style added. 

 

%PDF-1.6
%âãÏÓ
1 0 obj
<</Metadata 2 0 R/OCProperties<</D<</ON[5 0 R]/Order 6 0 R/RBGroups[]>>/OCGs[5 0 R]>>/Pages 3 0 R/Type/Catalog>>
endobj
2 0 obj
<</Length 3397/Subtype/XML/Type/Metadata>>stream
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 6.0-c002 79.164460, 2020/05/12-16:04:17        ">
   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <rdf:Description rdf:about=""
            xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
            xmlns:illustrator="http://ns.adobe.com/illustrator/1.0/"
            xmlns:xmp="http://ns.adobe.com/xap/1.0/"
            xmlns:pdf="http://ns.adobe.com/pdf/1.3/"
            xmlns:dc="http://purl.org/dc/elements/1.1/">
         <xmpMM:RenditionClass>proof:pdf</xmpMM:RenditionClass>
         <xmpMM:DocumentID>uuid:7d9c780a-68e8-49b8-8ac2-57ee75c99122</xmpMM:DocumentID>
         <xmpMM:InstanceID>uuid:3cfe8f29-f6e4-4e60-82d1-caae093a436b</xmpMM:InstanceID>
         <illustrator:CreatorSubTool>Adobe Illustrator</illustrator:CreatorSubTool>
         <xmp:CreateDate>2020-11-23T13:38:29+08:00</xmp:CreateDate>
         <xmp:CreatorTool>Adobe Illustrator 24.2 (Windows)</xmp:CreatorTool>
         <xmp:ModifyDate>2020-11-23T13:38:29+07:00</xmp:ModifyDate>
         <xmp:MetadataDate>2020-11-23T13:38:29+07:00</xmp:MetadataDate>
         <pdf:Producer>Adobe PDF library 15.00</pdf:Producer>
         <dc:format>application/pdf</dc:format>
      </rdf:Description>
   </rdf:RDF>
</x:xmpmeta>

 

 However, I see PDF in the actual Object file at the top of the vector smart object file looking at the .ai file via a text editor.  If I open the vector smart object via a text editor. I do not install AI. I have set extension .ai to open with Notepad++ on my windows machine.

 

The bottom Layer in the work document is a rectangular Shape layer the Object size that has a  solid fill layer. color.

image.png

 

image.png

 

 

However, when I create a smars object layer with a two layet object like that the Object opens with editObject synchronously. Ther is a document switch.   

 

When I edit the object and have Photoshop update the template the Object that failed to open with editObject When my script  uses editObject for the next replacement image the updated smarts object layer the object work file open with editObject in the Open Smart object function.  I do not need to add the open command for the work file to speed processing up.

 

Normally editObject in my open smart object function opens the object work file into a photoshop as work document for the object.   There seem toe be some exceptions.  I'm trying to determine why some object do not open  synchronously for Mockup scripts next steps are designed to update the smart object work file. . For some reason the first time some smart object layers have editContent used on them do not open  in Photoshop  synchronously. 

JJMack

Likes

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
Reply
Loading...
Jan 03, 2021 1
Engaged ,
Jan 04, 2021

Copy link to clipboard

Copied

 
Sorry my message didnt post a couple times, then i got some kind of ban and needed to wait a hour. Kinda stupid dumb it does a page refresh and not post the message. Twice did i made a long new post, both times lost 😞 This forum still isnt working really well i guess.


Anyways here's the link. https://we.tl/t-amPqhIM4pC
I had it ready forgot about, but than it also got delete twice because of the prior post issue

I finally got it working again. I now open the smartobject between the 2 dialogs. Somehow the GUI does update then properly. I than use command to switch documents. I also delete the prior delete file to keep smaller when saving. I thought this part of the code would make the script run longer. But it actually faster then. Sometimes its about 1 sec faster running it with 6 designs.

It was quite weird actually, because at one point i already had it working. Then for extra check i saved the main template closed photoshop opened it again and then suddenly it would run. So this time i did save the script file into a new version from the point it was working and then started fine tuning. 

I notice that when functions are below in the script this can cause issues. Now i make sure the functions are earlier in the lines. Im not sure im 100% cirrect on this, but it seems this does influence the script sometimes.

Im also suspending the history, i believe this also speeds things up since they dont neet to be written to the log and the GUI.

Below version works, ive tested it multiple times now while opening and closing the main file and restarting Phososhop a couple times. It works just a bit nicer now then the other version i had yesterday, there i opened the smartobject from the start manually.
 
after i waited a day now it still wont allow me to post a comment here?!? Im trying this with a linked version of the script. I also had to reply to the first comment. I cant reply to your latest comment, it will refresh and nothing is posted. Therefor i tagged you using your name, that way im sure you are notified

Likes

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
Reply
Loading...
Jan 04, 2021 0
Most Valuable Participant ,
Jan 05, 2021

Copy link to clipboard

Copied

The problem is strange and does not always fail the same way.  The Problem seems to be related to some smart object layer and the way the are crated.  For example the only template I had where the smart object did open right away with 

 

 

 

 

		runMenuItem(stringIDToTypeID('placedLayerEditContents'));

 

 

 

 

was one I download from the web.  When I replicated the Template on my Windows machine it did open right away.  However, if I ran the same batch job sever time in a row occasionally the object would fail to open right away in the middle of a batch but  the code I added to wait for it to open or to add a open would  solve the problem most of the time. Waiting always seem to work however occasionally other problems would happen if I added the open command. Perhaps I open  and update the object  then the opened again open again and missed up my script because it was the processing the wrong document.

 

Now the Template you posted only one smart object layer needs to be updated  but the template has several smart object layers on  the top of the stack.  My mockup scripts are design to only update the top of the  layers stack smart object layers.  It is easy to convert  Mockup templates to be compatible with my scripts design.  So I modified your template.  I simply grouped all the layer above the Background into a group named Mockup. I the used Ctrl+J to dupe the smart object layer that needs to be updated and move the copy out of the mockup group to the top of the layer stack and I removed the masks changed opacity and fill to 0 and turn off its visibility. 

 

Right away the Smart Object fail to open but my script had not problem populating the template.   I then replicated  your template.  I saved the smart object work file as a PSD File.   I them placed the PSD file into the replicated template above the smart object layer that needs the replacement. and did a Ctrl+J to dupe it and moved the dupe to the top of the stack set fill and opacity  to 0 and turn off its visibility. and deleted the old top of the stack smart object layer..  I then  moved the vector layer mask off of the smart object layer  to the placed psd smart object layer and the deleted the smart object layer that needed to be replaced.  I clipped the Smart object layer to the Phone case layer at the sized the object with a transform to cover the phone case and Saved the Template.   On my machine this template object open right away. Running many batches occasionally it  may fails to open.    This is a strange problem.  I have not test in PS 2020 just 2021.

 

Here is a link to a zip file the has my text templates and scripts Mockups.zip 

JJMack

Likes

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
Reply
Loading...
Jan 05, 2021 0
Most Valuable Participant ,
Jan 05, 2021

Copy link to clipboard

Copied

I have now tested with CS6,  CC 2014, CC 2018, CC 2019, PS 2020 and PS 2021.  All seen to fail to open the Smart Object Layer's  object that your Mac created right away like the one I had downloaded.  Where in PS 2021 version 22.1 if I  wait using a wait till message the object will open.   In prior Photoshop the object never opens I have to add the open for the temp work file that was created by Photoshop for placeLeyerEditContents  but did not open.  

 

So the scripts in my toolkit work in Photoshop version prior to PS 2021 on windows machines.  I'm not positive they will on Mac for I'm not sure of where Photoshop created the temp work file on a mac.  This is what I use for Windows it may be the same for  Mac. depends on Forder.temp beint the place the file is created

 

 

var workFile = new File(Folder.temp + "/" +  name);  // May work for both Windows and Mac

 

 

 

PS 22.1 can occasionally have problem if I add the Open Command. However,  adding the open performs faster than waiting for the object to eventually open So I will not be changing my scripts for waiting requires human interaction which is not appropriate for a batch process.

 

I look at you script its seem to work on my machine but has issues with Place scaling images  and it  leave the object open.   I particularly do not like templates that have smart object  layer where the object is layered and to populate  the template you have to edits late within the object. Templates like that are too hard to use and  requite a custom script for automation.  It is far easier to create templates that simply need the smart object replaced.  So I simplified your Template or the one you purchased or downloaded.   I rasterized some layers  and moved the tool bar layers into the template from the object and added a camera layer.  This template can be batch processed with my script and if you use its edit option replacement images can be any size. The phone screen will be filled with image content.  If replacement images  are Phone size my scripts default isuse  Replace content not edit here the template. samsung-s20-mockup-xxx.psd 

 

http://www.mouseprints.net/old/dpr/samsung-s20-mockup-xxx.psd 

JJMack

Likes

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
Reply
Loading...
Jan 05, 2021 0
Engaged ,
Jan 05, 2021

Copy link to clipboard

Copied

@JJMack 

 

thanks once more! I didnt create this template so im not sure on what machine it was created. When i started this script i started coding on OSX using 2018cc and at one point it worked like i wanted it. Then i started tweaking it and it kept failing also on windows using newer version of PS. It took me couple days and hours each day to do tests and made many variants of this script. The version i linked works fine on Windows now, i still need to test OSX.

 

Concerning the placed object, i dont think it matters on what machine it was created. Since the PSB is not linked it should open on any machine. Only when its linked and you switch OS's then the path becomes an issue.

 

About the order in the templage. Since i didnt create it i didnt take to much notice of it. Since i dont really use this very much myself. I started this script to help someone which wanted a variant of replacing smartobject, then i noticed several people asking to use this for mockup designs.

The way always works for me is open the smartobject once. Then select the layer above the phone and under the top placed AI file, the phone battery and charge part. I understand you method of duplicating and placing it on top. Yet, i dont think it really matters in the end. If you make sure what layer is selected it should always work.

 

Ill try you updated version as well, see if it also works for me here

Likes

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
Reply
Loading...
Jan 05, 2021 0
Engaged ,
Jan 05, 2021

Copy link to clipboard

Copied

I tried you mockup setup, but ran in the issue with not having the obj1,obj2,obj3 subfolders. I dont think i like this setup. It makes things to complicated. I also dont quite understand the need why the files which need to go in the smartobject need to be in subfolders?! It asks for 3 folder, but i selected a folder with 10 items?! I guess that is tailored to those examples i saw on you linked page. I see 3 images inside a main page, thats the only thing i could think of why it wants 3 subfolders.

 

What i do like is how you setup that dialog, picking a base file, then pick the files need to go in the smartobject. Thats very nice!

Likes

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
Reply
Loading...
Jan 05, 2021 0
Most Valuable Participant ,
Jan 05, 2021

Copy link to clipboard

Copied

You can use the BatchReplaceOneObject.jsx in my package when you only need one smart object layer replaced. You do not need to create the sub folders smart object layers  replacement queues obj0, obj1, ..., objN.

 

The BatchMockupTemplates.jsx script can populate any number of templates  that have some number of  smart object layer  0, 1, ..., N that need to be populated with replacemennts.  The top of the layer stack consecutive smart object layers objects.   Layer stack level 0, 1, ..., N. the subfolders  obj0, obj1, ..., objN contain  the queue  of replacement image for each of the smart of the smart objects layers.  You could have 100 psd templates that have a 100 smart object layer on the top of the layer stack,  and have 100 replacement image is each of the objN subfolders.  The script would populate the 10,000 replacement images into the 100 Templates. Each of the 100 Templates would be populated 100 times . The Script would save out 10,000 populate jpeg files. 

 

My script are for batch processing templates. If you only need one output file populate the template manually.  If you want to batch process templates you need to have a template design that is easy to populate with automation and some setup will be required. Use the Help button in my Scripts dialog.

 

It would be very easy to populate the template you posted manually but it harder then it need to be, For you have to open the smart object tanh know how to update the object.  Update the object and commit the update. It would be easier if all you needed to do was replace the smart object content.

JJMack

Likes

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
Reply
Loading...
Jan 05, 2021 1
Engaged ,
Jan 06, 2021

Copy link to clipboard

Copied

@JJMack 

 

Well i tried my working windows version of the script on OSX with 2018cc and there it wont work. Even when i place the "placedLayerEditContents" on the second line in the script right after #target photoshop, it doesnt open until everything else has run. This is really strange! I added waits,  refresh and sleep, nothing helps.

 

Then i tried your function "openSmartObject", which does work in this scenario. This function does not work when i use it on windows. First i that because of the alert, it slows things down. This happens on Windows actually, some script work when i add an alert. But i also tried your function without that alert it gives about opening. It still runs just fine on Mac. perhaps this has something todo that on OSX we see that open command right after "placedLayerEditContents", i dont think i see that on Windows. I need to check it. Then it would make sense why the app.runMenuItem doesnt work

 

So tonigtht i try this new version on Windows again and see if it work with your function. I just need to try it again. Otherwise i use 2 method for the 2 OS's the "app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));" works fine on Windows. So im thinking of doing it like this:

 

 

if(isMac()){
                openSmartObject (theLayer)
            } else {
                app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
            }

 

 

 So if we have a Mac then we use JJmack script if we have Windows we run this command. Its best of both worlds 😉

Likes

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
Reply
Loading...
Jan 06, 2021 0
Most Valuable Participant ,
Jan 06, 2021

Copy link to clipboard

Copied

And now Apple has its own processor M1.  Adobe stated they will have a Photoshop version for it sometime in 2021. 

 

I believe I made the right choice in 2000 that is Microsoft. Microsoft  respects their users, knows they need to fix bugs and develop Windows it a way that  users old software will run.  If not possible help users  providing compatibility  troubleshooters, compatibility modes.

JJMack

Likes

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
Reply
Loading...
Jan 06, 2021 0
schroef LATEST
Engaged ,
Jan 06, 2021

Copy link to clipboard

Copied

@JJMack 

 

Im not sure what this M1 chip has to do in this case? I dont want to start a OS thread, im in favor of OSX actually hahaha

 

However, the earlier function i showed works now on both OS's. So your function seems to make it work on OSX while the since runMenuItem runs smooth for me on Windows. Perhaps its because of faster machine vs older (12year old) machine.

 

PS Photoshop runs on the M1 using Rosetta. I dont know if you have seen any vids about this new chip. But its going to crush intel! The airbook already crushes the 2016 macbook pro.... Thats a light machine crushing a so called pro machine. Im really curious what the feature will bring if they come with more powerful versions. On youtube many of the tech reviewers also show super great specs, numbers and comparissons.

Likes

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
Reply
Loading...
Jan 06, 2021 0
Adobe Employee ,
Jan 05, 2021

Copy link to clipboard

Copied

test

Likes

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
Reply
Loading...
Jan 05, 2021 0
Engaged ,
Jan 05, 2021

Copy link to clipboard

Copied

This issue happened when i was posting message quite fast within the hour. Thats also why i got the "wait 3600 second" warning/error.

 

I also see a lot of errors when i post code which have comments in them from either community links or other website. It then shows an error about "faulty html" code or so. I did make a screengrab of that error i get a lot when pasting script as Javascript. Sometimes when i checked the pasted script, i noticed parts where missing. But also i noticed sometimes parts where added. I looked like it grabbed text of the forum link i pasted in the script as a comment.

This is the error i see a lot when pasting script which has links in thereThis is the error i see a lot when pasting script which has links in there

What i did see a lot was that when i pressed post, the page would reload and nothing showed. No error not hint of bad embed text nothing, my complete message was gone. This happened quite a lot of times. Then eventually after witing a day i still could reply to a post made by JJMack. I could only reply to the main question on top.

Could it be that threads have some kind of limit of responses? Because i was posting quite a lot script code each time, perhaps there something like a "max character count", i dont know. You would need to ask the developers of the forum.

The fact that you think its posting and it doesnt is nasty. You cant go back and you basically lost your complete message.

 

 Hope this helps to understand what i was experiencing and perhaps can help to backtrack the issue.

 

PS there was actually another weird error i got. Its an error where it also stated that "invalid HTML" is used and that its being highlighted, yet nothing is highlighted then?!

Likes

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
Reply
Loading...
Jan 05, 2021 0
Most Valuable Participant ,
Jan 05, 2021

Copy link to clipboard

Copied



@schroef  wrote:
"… Sorry my message didnt post a couple times, then i got some kind of ban and needed to wait a hour. Kinda stupid dumb it does a page refresh and not post the message. Twice did i made a long new post, both times lost 

:(

 This forum still isnt working really well i guess. …"


test

Likes

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
Reply
Loading...
Jan 05, 2021 1
Engaged ,
Jan 05, 2021

Copy link to clipboard

Copied

@pixxxelschubser 

thanks for trying, i just posted my experience above and added some comments about what happened.

Sadly i didnt screengrab every error i got. Only the "wrong/bad HTML" code error

Likes

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
Reply
Loading...
Jan 05, 2021 0