Copy link to clipboard
Copied
Hi Team,
I'm developing an internal extension for my company. The extension allow user to open psd document inside it. But I'm facing an weird adnormal case. When user create a new PSD document and doens't save it, then continue to open an existing document from my extension. Following error message is shown up.
"The document has not yet been saved."
Currently, I'm using app.open() function to open an existing document with known file path. Any idea how I can overcome above incident?
Thanks for reading my question,
Copy link to clipboard
Copied
Hi, you've also posted this message over in the Flex forum. So which is it? Does the extension run in PS or in Flex?
If you're running it in Flex, you might need to explicitly target photoshop every time your users trigger the script.
Copy link to clipboard
Copied
Hi Jef,
I posted in Flex by mistake and cannot delete it. Sorry for my bad.
I'm doing this in Photoshop by the way. Do you have any how to resolve this?
Thanks
Copy link to clipboard
Copied
I'd like to help think along but I don't have an answer based on your information. 🙂
Ok, so it runs in Photoshop.
What do you mean by Extension? Are you using any of these: CEP, CC SDK? Or are you writing everything "from scratch?"
A first guess without looking at any of your code (hint hint...) is that your extension might not check the currently opened documents before doing something. Ie: when people use your extension, it does things without first checking it's environment. That's just a guess though... If you don't check whether there are more documents opened in PSI think you should add one. In which case, look at activeDocument.saved and activeDocument.path to see whether something is saved or not and app.documents.length to check the number of currently opened documents.
All the best!
Copy link to clipboard
Copied
Hi Man,
Thanks for your reply. Although, I didn't provide a lot of details. But you seem to be getting very close to my problem.
Following is the code having the error with. Basically, I use this code to detect if target file is openned. If not, I will open it with respective filepath. When the loop come up with unsaved file, it seem to be failed in fetching file's properties such as `fullName`. You can see I'm trying to work around to include the issued code inside a try/catch to prevent error.
It's just temporary solution. I would like to find out a absolute solution for this issue.
Hope you can help me to firgure out.
Thanks so much for your time and your support
findDocument: function (file) {
for (var i = 0; i < app.documents.length; i++) {
try{
if (app.documents[i].fullName.fsName === file.fsName) {
return app.documents[i];
}
} catch (e){
return;
}
}
return;
},
Copy link to clipboard
Copied
Spent some time thinking...
In CEP 8 HTML Extension Cookbook, they mention that Photoshop has a thing with unsaved documents.
When you go to the page and search for documentAfterActivate you should get only 1 result.
It shows a table of standard events photoshop looks out for.
For documentAfterActivate, the application returns something different depending on whether the document was saved or not... And Photoshop by default does not support this event. (yet?)
If all the above is correct and applies to you, that could be why it doesn't work... It's just not supported.
I then found this little piece of code by Dieter Holvoet online. It's another way of working around the crashing by checking for unsaved files. By prototyping, he adds a function to "File" that when called loops over all documents and checks that any opened document has a full path. If not, it displays the alert. This wouldn't solve the problem directly, but work around it by educating your users. 🙂 Could be worth a shot...
File.prototype.asDocument = function() {
var document = false;
for(var i = 0; i < app.documents.length; i++) {
switch(app.documents[i].getFullPath() ) {
case false:
alert("Please make sure no unsaved files are open before continuing.");
exit();
case this.getFullPath():
document = app.documents[i];
break;
}
}
if(!document) {
app.open(this);
document = app.documents[0];
}
return document;
};
All the best!
Copy link to clipboard
Copied
Hey Man,
I just saw your comment today. Spent whole last week to do a release and bug fix, haven't followed up your comments sooner. Sorry, bro.
Basically, your code sample is working around the issue. Same thing for me, I wrapped app.documents[i] in try/catch to prevent error. Because it's critically issue, just display a confused error message but not affect anything else.
As you said, it doesn't get supported at the moment. So we only can keep it in mind and hope for some proper solution in next CEP version.
Thanks,
Copy link to clipboard
Copied
yw, I'm happy you found something you can move on with. Even though it's not perfect. GL!
Copy link to clipboard
Copied
I would think a message like "The document has not yet been saved." Would come from a script or extension that need to use the Document backing files path for some reasons but finds the current document is a new document that has never been saved so there is no backing file. If the user tried to save the document and it did not you need the find out why save as failed. If save as works photoshop changes the document name to reflect the save file and there is a recorded backing file.
Here I opened a RAW file as an object. ACR open a new document with the mane ImageName-1 no CR2 extension no backing file exists it a new document the document name in Photoshop has no .extension. I added a sharpening adjustment layer then used the shortcut Shift+Ctrl+S Save As and saved it to my desktop as a psd file. You can see the open document name has been changed to ImageName-1.psd. I closed the document and opened the same RAW as a normal Background layer. Again ACR open a new Document ImansName-2 there is no backing file. I then Ran the Image Processor Pro plug-in to save it. I was expecting it to fail for it was a new documen ImageName-2. Image proceesor pro did fail but not because it was a new document. Image Processor Pro found the Document was opened from c:\ImageName.cr2. Image processor pro was not trying to save ImageName-2.psd It was trying to save ImageName.psd in the root of C:. It failed because I keep that test raw file in the root of my boot disk. My user ID does not have write permissions there. Still the meaasge you saw was because the current document was new never saved.
</ImageProcessorProSettings>
2020-08-31T09:35:56 - Processing: LO2G5037-2 copy
2020-08-31T09:35:56 - saving C:\LO2G5037.CR2 as C:\LO2G5037.psd
2020-08-31T09:35:56 -
==============Exception==============
Message: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
- Could not save a copy as "C:\LO2G5037.psd" because the file is locked, you do not have necessary access permissions, or another program is using the file. Use the ‘Properties’ command in the Windows Explorer to unlock the file.
Copy link to clipboard
Copied
Hi JJMack,
Thanks for your detail explaination. But I'm pretty sure this is not my case.
If I work on Photoshop without extension, I can open any existing files without caring about unsaved openning files.
So it should work same way with using extension. Let me know if you need any further information.
Thanks,
Copy link to clipboard
Copied
If you open a file the file exists it is not a new document. If you duplicate it you give the duplicat document some new name and the document has the same content as the original. However it is a new document that has never been saved. There is no file on you disk for the document till you save the docment. Then it is not a new document for there is a file on you disk. There may be an exception. If you use save as and save a layerd document as a jpeg or png or some other flat file the flat file will be save. However, the document still open in Photoshop will be layered and still new for there is no file on you disk backing the layred document.
Copy link to clipboard
Copied
Hey man, any luck solving this yet? We're all rooting for you here. 😉
Copy link to clipboard
Copied
Find more inspiration, events, and resources on the new Adobe Community
Explore Now