I have got a toolbox full of models to run from one script.
Is there any code that calculates the location of script from which I can get the path to my toolbox?
Script and models are imported if that matters. Toolbox is going to be used on a few computers and running a script is more nice way than searching for models.
1 Answer 1
Since your script is imported into the toolbox, this will provide the path to the toolbox
pathname = os.path.realpath(__file__)
pathname = pathname.split(".tbx",1)[0]+".tbx"
-
If you're operating on paths, just use
os.path.basename()
. This will work properly if the path contains.tbx
.Paul– Paul2016年12月17日 01:42:00 +00:00Commented Dec 17, 2016 at 1:42 -
@Paul I tried both methods you recommended, I had imported script but it gave me a path like
C:\Windows\system32\script
while toolbox is located in for example D:\Data\Folder\Pavel Pereverzev– Pavel Pereverzev2016年12月18日 22:07:31 +00:00Commented Dec 18, 2016 at 22:07 -
@TunaSammich, I got the result like in my comment belowPavel Pereverzev– Pavel Pereverzev2016年12月19日 08:12:41 +00:00Commented Dec 19, 2016 at 8:12
-
@PavelPereverzev, it's possible you'll need to grab
__file__
before you import the toolbox.Paul– Paul2016年12月19日 16:55:45 +00:00Commented Dec 19, 2016 at 16:55
Explore related questions
See similar questions with these tags.
arcpy.ImportToolbox()
and then run the models as necessary. What do you want to do now?arcpy.ImportToolbox()
which was made on my computer will not run on the other one because of another location. I.e. I havearcpy.ImportToolbox(r"D:\Data\Folder\toolbox.tbx")
and other user placed in E:\Data\NewFolder\toolbox.tbx. In this case script will give an error. So is that possible to calculate the path to the only script?