Copy link to clipboard
Copied
Hi all, I'm running a routine to place a series of PDF files, some of which AI doesn't like for whatever reason. I'm trying to get remove the placedItem object I create if the file fails to place properly, but I get the attached screenshot error:
Here is the snippet of code:
var placeFile = function(doc, file) {
var placedItem = doc.placedItems.add();
try {
placedItem.file = file;
}
catch(e) {
placedItem.remove();
return -1;
}
}
Any thoughts? If I don't remove the item, and I try to open the resulting file, I get missing link errors. Thanks.
Copy link to clipboard
Copied
Hi Brian, I'm not at my computer now but I'd be happy to test. It would really help if you had a pdf example file that Illustrator doesn't like, so I could replicate your situation. Also, if you add $.writeln(placedItem); above placedItem.remove() in the catch block? Does the writeln error?
- Mark
Copy link to clipboard
Copied
hmm...your script works fine here. I'm on Windows 11, ai version 26.0.
are you on mac?
Copy link to clipboard
Copied
This dialog may be caused by some strange fact that maybe when the file is assigned a missing file, it produces a missing file 'procedure' right away, possibly blocking the catch(e) {} block (???).
So first, try to remove the user interaction level with app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
But suppose that it still fails and does the problem. You can prevent the issue by checking that your file that is going to be added as a link does indeed exist in the first place with file.exists. This way if it does not exist, make no attempt to add a placed item at all.
Copy link to clipboard
Copied
I suspect @Silly-V has nailed this one. @brianp311 does it solve the problem if you add the line
if (!file.exists()) return;
after the first line?
- Mark
Copy link to clipboard
Copied
Waiting for client to get back to me with a bad place file. I can't re-create the problem either. Will keep you all posted. Thanks for the food for thought thus far. But not sure that's the issue, since I'm getting the files from a Folder.getFiles() call.
Copy link to clipboard
Copied
OK, definitely is related to something with the path. From an error log:
Thursday, February 03 2022 19:35:17: Could not place file: 763-HU3535-4215-52-100-25_Binding.pdf: Error: Unable to set placed item's file, is the file path provided valid? Or try to use the raster item instead.
Thursday, February 03 2022 19:35:18: Could not place file: 763-HU3535-4215-52-100-25_Front%20Short.pdf: Error: Unable to set placed item's file, is the file path provided valid? Or try to use the raster item instead.
I'm calling getFiles() on a PC path something like:
var fol = Folder("H:/05 TopLevel/2021 Product/Illustrator Scripts/00_PDFS/Hot Folder)";
var allFiles = fol.getFiles("*.pdf");
for each allFiles, run script above.
Some files place, and some do not. For the ones that do not place and throw the above error, I try to remove the empty placedItem object I created but got the initial error.
Very weird.
Copy link to clipboard
Copied
Hi Brian, are you able to successfully place, say, file "763-HU3535-4215-52-100-25_Front%20Short.pdf" manually?
Copy link to clipboard
Copied
Yes, I can even place them programmatically, but I'm using Folder.selectDialog() to get the initial folder path, rather than hardcoding the path in. I can't recreate the issue the client is having.
Copy link to clipboard
Copied
Hmmm that's very hard to troubleshoot if you can't reproduce. Does it get the same error on the same files if you run script a second time on the client's machine? Wondering if it is something to do with the state of the hot folder when the script is triggered. Maybe running script again will not error, or will error on different files due to script triggering while some pdfs are only partially copied. I'm grasping at straws.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
can you share the trouble pdf file? or does it have confidential info in it?
Copy link to clipboard
Copied
I will PM one to you and @m1b
I also dug up this old thread at the PARM error: https://community.adobe.com/t5/illustrator-discussions/an-illustrator-error-occurred-1346458189-parm...
Doesn't seem like there's any rhyme or reason to it.