Make sure PDF is saved before script proceeds

Contributor ,
Oct 27, 2020

Copy link to clipboard

Copied

I have a script that writes a PDF to the user's desktop, then calls a VB script to attach the PDF to a Slack post. Most of the time it works just fine but occasionally the saved PDF is a zero-length file that Slack can't handle. My inclincation is to add some logic to check file.length before proceeding, but I'm not what to do if/when the file.length is zero. Pause for a few ticks and try again? 

 

Hoping someone else has encountered something like this.

 

Bob

TOPICS
Scripting

Views

74

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

Make sure PDF is saved before script proceeds

Contributor ,
Oct 27, 2020

Copy link to clipboard

Copied

I have a script that writes a PDF to the user's desktop, then calls a VB script to attach the PDF to a Slack post. Most of the time it works just fine but occasionally the saved PDF is a zero-length file that Slack can't handle. My inclincation is to add some logic to check file.length before proceeding, but I'm not what to do if/when the file.length is zero. Pause for a few ticks and try again? 

 

Hoping someone else has encountered something like this.

 

Bob

TOPICS
Scripting

Views

75

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 27, 2020 0
Enthusiast ,
Oct 27, 2020

Copy link to clipboard

Copied

Hello Bob,

Check out all three answers on this post to see if they'll help you out.

https://stackoverflow.com/questions/7161739/how-can-i-check-if-a-file-exists

 

Regards,

Mike

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 27, 2020 0
Contributor ,
Oct 29, 2020

Copy link to clipboard

Copied

It's not a file.exists problem. The file exists but, once in a while, file.length is zero

Slack won't accept that, understandably.

I'm trying to use $.sleep to build in a short pause between executing fileExport and starting the Slack upload process. But I'm not clear on one important question: Does pause the script execution also pause the fileExport process? I wouldn't think so but I just don't know.

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 29, 2020 0
Enthusiast ,
Oct 29, 2020

Copy link to clipboard

Copied

hi Bob,

 

Here's a post to check to see if the file size has changed.....maybe you can do the upload when the file size has stopped changing.

 

https://stackoverflow.com/questions/28298946/vb-script-to-check-if-the-file-size-has-been-increased-...

 

if you're doing the file export and move is the same script you could try asynchronousExportFile, and use waitForTask(); before the upload process starts.

 

below is an example copyied from one of my scripts.

 

 

 

task = doc.asynchronousExportFile(ExportFormat.PDF_TYPE, File(myFolder +'/'+ my_layer + mySuffix + "HR.pdf"), false, export_preset4);
task.waitForTask();

//Do your upload after the export has completed.

 

 

 

 

 

 

Regards,

Mike

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 29, 2020 0