How to make file paths configurable within an ArcGIS Python Add-In?

875
5
07-11-2013 11:58 PM
IbraheemKhan1
New Contributor III
I have a project folder with sub-folders containing several files on my hard disk which I read from within my Python Add-In, its hard coded e.g.:

dem = r'C:/project/raster/dem'

and Add-In is in

r'C:/project/Add-In'


folder. I am using os.path options to get local path with all folders located within Install folder of Add-In. But this isn't feasible for case where I have to update scripts and provide it to others as it involves transfer of gigabytes of data, which goes into AssemblyCache with each install. Please suggest how to make file paths configurable within Add-In to read files outside it.
Tags (2)
0 Kudos
5 Replies
DuncanHornby
MVP Notable Contributor
Just thinking off the top of my head here but could you have a very simply text file which lists paths to other locations and include that into the AddIn. Then your AddIn code looks for this file and reads from it allowing you to store your data elsewhere?

I have not used Python AddIns so not sure how easy it would be to include a separate file?
0 Kudos
JasonScheirer
Occasional Contributor III
Yeah, I think including a text file with a path in the add-in would work. Another option is using a registry key.
0 Kudos
IbraheemKhan1
New Contributor III
Yeah, I think including a text file with a path in the add-in would work. Another option is using a registry key.


If I understood correctly, how would including a text file with a path be different than simply hard coding paths in the logic script?
The issue at hand is to read files outside the folder where addin is placed. So it would be something like this:

say addin is in following folder: 'C:/proj/addin/addin.esriaddin'
and I want addin to recognise files in: 'C:/proj/data/raster1' or 'raster2.....'

In above instance, data and addin are placed in C drive but I want addin to be configured in a way so that it can read data even if it is placed in D or E or F drive without the need to hard code the root directory path in logic script. This way, user can simply place updated addin in the designated folder irrespective of what drive it is residing in.

Please let me know if my answer isn't clear.
0 Kudos
RichardFairhurst
MVP Honored Contributor
If I understood correctly, how would including a text file with a path be different than simply hard coding paths in the logic script?
The issue at hand is to read files outside the folder where addin is placed. So it would be something like this:

say addin is in following folder: 'C:/proj/addin/addin.esriaddin'
and I want addin to recognise files in: 'C:/proj/data/raster1' or 'raster2.....'

In above instance, data and addin are placed in C drive but I want addin to be configured in a way so that it can read data even if it is placed in D or E or F drive without the need to hard code the root directory path in logic script. This way, user can simply place updated addin in the designated folder irrespective of what drive it is residing in.

Please let me know if my answer isn't clear.


What you are describing makes no sense.  You have to program a path somewhere that is hard coded for at least the root if you are not allowed to deduce the path from the add-in location.

Think about it.  Lets say I want to make phone call to someone in my own area code.  I don't have to tell anyone what the area code is because we can all deduce it from my location.

Now lets say I want to dial the same number and not give the area code, but I want the phone to connect with someone in a different area code altogether.  How do you expect the phone company to program their phone system to do that?  Randomly try every area code for me until the call goes through where I wanted?  They could try that approach, but I won't be providing any confirmation that they have connected me to the correct party.  If more than one connection is possible, how will they know they got the right one if I won't give them any feedback?  Do I have a right to expect my phone call to go through under these conditions?  What could do this other than a magical mind reading app?  If I could successfully develop that kind of app I would already have a Nobel prize.

This is how you have described your program requirements so far.  Describe any information I actually was expected to provide to the phone company or the kinds of feedback loops and confirmations I was suppose to give them in the scenario above that would make my phone call possible.

Fianlly, you do realize that if you are wanting the user to access data on a network drive that you should not use a drive letter at all for the path ever.  Drive letters are dependent on the local computer.  What you must specify is the domain URL to the network server (which is what the drive letter actually points to).  The path:  r'//myserver/files/data/...' will go through on any computer in my network with access permissions to myserver in my domain.  A domain name server can be used to abstract the path further, making the path independent of an actual specific server, so that the domain administrator can transfer data and repoint all users to a new server keeping the same path for his end users without touching any local machines.
0 Kudos
T__WayneWhitley
Frequent Contributor
0 Kudos