Select to view content in your preferred language

View exported file from Python Toolbox?

1655
5
Jump to solution
03-08-2021 09:29 AM
MichaelMorisette
Occasional Contributor

I've noticed that when you export a layout to PDF in Pro, it gives you a handy option to "View exported file."  Is there a way to add this prompt for a file generated from a Python toolbox?

Capture.PNG

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

You could set a boolean parameter named 'View exported file' in your tool, and then at the end of your script you set a conditional that checks if the boolean is true or false and do an os.startfile('exported path') if its true.

View solution in original post

5 Replies
DanPatterson
MVP Esteemed Contributor

they aren't part of a tools parameeters

Layout—ArcGIS Pro | Documentation

exportToPNG (out_png, {resolution}, {color_mode}, {transparent_background}, {embed_color_profile}, {clip_to_elements})


... sort of retired...
0 Kudos
jcarlson
MVP Esteemed Contributor

I've tried adding links via AddMessage and SetProgressorLabel, but the resulting link isn't a "live" hyperlink, whether to a URL or a file.

Getting a "completion" message to show up is probably something that would need to be done via the Pro SDK, rather than from a Python script. It would be a really great feature, though!

- Josh Carlson
Kendall County GIS
0 Kudos
by Anonymous User
Not applicable

You could set a boolean parameter named 'View exported file' in your tool, and then at the end of your script you set a conditional that checks if the boolean is true or false and do an os.startfile('exported path') if its true.

MichaelMorisette
Occasional Contributor

This did the trick!  Thanks.  I found os.open() didn't seem to work, but os.startfile() did what I needed instead.

# Open the PDF if the user wanted to
if parameters[2].valueAsText == "true":
os.startfile(pdfFile)

0 Kudos
by Anonymous User
Not applicable

Yikes! My bad on that one- thanks for catching it.  I had C#'s File.Open stuck on the brain for opening files.

I updated the post with your correction.

0 Kudos