Calling python scripts

218
4
Jump to solution
02-05-2025 04:28 PM
DanCrawford
Occasional Contributor

Apologies for what might seem simple but...
In ArcMap, it was simple to call a python script from another using execfile()

I need to recreate that in Pro but nothing I try works.  It doesn't matter if I'm calling a .py file or an embedded python script in a project toolbox. 
Some things I have tried:
from "//spatialfiles2.bcgov/work/FOR/RNI/DPG/!Tenures/Templates/ExhibitA.Pro/Python/ExportPDF.py" import pdf
or
sys.path.append('\\spatialfiles2.bcgov\work\FOR\RNI\DPG\!Tenures\Templates\ExhibitA.Pro\Python')
import ExportPDF.py

This is the path to my toolbox:
\\spatialfiles2.bcgov\work\FOR\RNI\DPG\!Tenures\Templates\ExhibitA.Pro\ArcGIS_Pro.atbx
and the tool I want to call is:
Script2

0 Kudos
1 Solution

Accepted Solutions
DavidSolari
MVP Regular Contributor

The official docs for ImportToolbox should cover that.

View solution in original post

0 Kudos
4 Replies
DavidSolari
MVP Regular Contributor

To call the function "pdf" in the file "ExportPDF.py" in the folder "//spatialfiles2.bcgov/work/FOR/RNI/DPG/!Tenures/Templates/ExhibitA.Pro/Python" the technique is:

import sys
sys.path.append(r"\\spatialfiles2.bcgov\work\FOR\RNI\DPG\!Tenures\Templates\ExhibitA.Pro\Python")
from ExportPDF import pdf

 

DanCrawford
Occasional Contributor

Thank-you, that works without error!
Something else, if you have time:

While running a script from a Pro toolbox, how do I call another script from the same toolbox?

This is my toolbox path:
\\spatialfiles2.bcgov\work\FOR\RNI\DPG\!Tenures\Templates\ExhibitA.Pro\ArcGIS_Pro.atbx

and the tool I want to run is named SE4Linears

0 Kudos
DavidSolari
MVP Regular Contributor

The official docs for ImportToolbox should cover that.

0 Kudos
DanCrawford
Occasional Contributor

Thank-you again.