Designing a mapping process with efficient maintenance. Each point and polygon may have many documents associated with it. License level prevents attachments. One-to-many relationship to table of links is a possible solution, but hard to maintain for the non-gis staff using the end product. If the hyperlink or html pop up provided a link to open a folder, then all new documents in the future could just be put in that folder. I have searched documentation and the internet and saw two people doing what looked to be solutions - (a) creating shortcuts (.lnk) files for each folder and (b) someone actually able to open a folder. Neither seem to work. ArcMap 10.2 Basic license, file gdb holds features. Folders of documents at same "layer" as mxd. Relative paths checked. Have tried hyperlink scripts both python and VBscript, and sample popup css file with the // lines tweaked. Closest I've gotten was a windows explorer opening, but to c:\ not the desired folder. Or get "Cannot find "file://<correct-filepath-and-folder-name> Make sure the path or file name is correct." Or get nothing at all. Any thoughts or ideas welcome. Thanks.
Solved! Go to Solution.
Eureka!
Thanks, Dan for riding thru the pain.
This version works either with the mxd on local using data on network drive or with mxd on network drive with the data.
import webbrowser, arcpy, os
from arcpy import env
def OpenLink ( [HereYaGo] 😞
wksp = env.workspace
part_1 = wksp.replace("\\","/").split("/")[:-1]
part_2 = "\\".join(part_1)
final_path = os.path.join(part_2, "mainfolder",[HereYaGo] )
webbrowser.open(final_path)
return
The map properties hyperlink base is not needed, but the default gdb for the map must be set to this gdb. So when new maps are created and the feature class added, that setting and adding the script is needed. I'm suggesting to the client that the mxd is copied/save as new mxd and then modified if new layouts or what have you are needed.
I tried this in VB as the hyperlink script...the paths contained a final backslash ie c\temp\
Function OpenLink ( [HereYaGo] )
Dim path
Dim objShell
path = [HereYaGo]
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute path, "", "", "open", 1
End Function
In python, this translates to (be careful with the spacing, there are 2 before the indented lines.
import webbrowser
def OpenLink ( [HereYaGo] 😞
path = [HereYaGo]
webbrowser.open(path)
return
Thanks, but these are the sample scripts given in ArcMap, which no matter how I put the [HereYaGo] folder name only opens Internet Explorer on the home page, or if it reads the folder name it of course can't find the folder on the internet so it goes to a search page looking for that folder on the web. Yes, it works with c:\temp but can it work with relative path to the mxd? Wrote code to get the mxd path, remove the name of the mxd form the full path, add subdirectory, then the actual folder that contains all the docs for that point/polygon. Path IS the proper path to the folder I want. But doesn't open it. This code opens IE at home page.
import webbrowser, arcpy
def OpenLink ( [HereYaGo] 😞
mxd = arcpy.mapping.MapDocument("Current")
fullpath = mxd.filePath
chunks = fullpath.split('\\')
fpathpts = chunks[:-1]
fpath = "\\".join(fpathpts)
leftpath = fpath + "\\foldername\\"
path = leftpath + [HereYaGo]
webbrowser.open(path)
return
Kim,
Just thinking in the context of ArcMap's HTML popup... If the attribute of the feature is a url or link, similar to this, it will open windows explorer to the specified folder.
<a href="file://///computer_name/data/layerfiles">click</a>
Mark
Thanks, Mark, but that didn't work no matter how I tried computer_name and I didn't see how I could make that dynamic when the project is given to the client.
I did find one issue was 'the depth' of the folder and maybe that's partly due to Win7 and the libraries setup.
Moved the folder containing the mxd and the subfolder with subfolders of documents to root c:\ this code opens Window Explorer to the proper folder when the subfolder is hardcoded. When put in the Hyperlink Script function and leave the subfolder hardcoded (rtpath location), it still opens the correct folder. When I change the folder name from hardcoded to the attribute field, it goes back to Internet Explorer and doesn't open any folder. (I tried it with [HereYaGo] directly in the path statement and when that didn't work, moved it to a variable and that didn't work either)
import webbrowser, arcpy
def OpenLink ( [HereYaGo] 😞
mxd = arcpy.mapping.MapDocument("Current")
fullpath = mxd.filePath
chunks = fullpath.split('\\')
fpathpts = chunks[:-1]
fpath = "\\".join(fpathpts)
leftpath = fpath + "\\foldername\\"
rtpath = [HereYaGo]
path = leftpath + rtpath
webbrowser.open(path)
return
Check the video
Thanks, Dan. I see your code is a bit more concise and in your video I see it works. I made my code look exactly like yours and it still opens IE. What other setting 'in the background' do I need to track down? Inside ArcMap? Outside ArcMap? Hmmm, actually install 10.2 if that makes a difference (downloaded but didn't update, call me stupid.) But would that actually make a difference? And now I guess have to ask about the next release if the client is upgrading will it change anything?
Kim can you do a screen shot of your field rtpath = [HereYaGo] ... the only way it didn't work for me is if the path didn't end in a / (ie /somefolder/ ) I did nothing else to get it to work...If you have a convoluted or a network path, maybe everything is out the window...but at least get it working with files in a local folder first.
Dan, here's a shot with your code and the attribute in question. I have tried every possible combination of slashes or no slashes. Here's the screen shot you asked for. I've discovered the path information in the script does not override the Hyperlink base in Map Document Properties. Nor can it be relative (??). So if I repeat c:\xxx\yyyy\DevilsLakeSites\<folder2hyperlink2> in the script and c:\xxx\yyyy\DevilsLakeSites\ in the Hyperlink base, the hyperlink works. Is there a way for script to be dynamic and not rely on the Hyperlink base so that every time yyyy (which is the main project folder with mxd using relative paths) is moved the new user doesn't have to update the Hyperlink base?
Using this in the hyperlink script it works on local machines. Haven't been able to get it to work over a network.
import webbrowser, arcpy
def OpenLink ( [HereYaGo] 😞
mxd = arcpy.mapping.MapDocument("Current")
part_1 = mxd.filePath.replace("\\","/").split("/")[:-1]
part_2 = "/".join(part_1)
final_path = part_2 + "/mainfolder/" +[HereYaGo] + "/"
webbrowser.open(final_path)
return
I thought if I changed it to the gdb's location (workspace) it would work over network, but no. Both versions over network open IE searching and not the folder.
import webbrowser, arcpy
from arcpy import env
def OpenLink ( [HereYaGo] 😞
wksp = env.workspace
part_1 = wksp.replace("\\","/").split("/")[:-1]
part_2 = "/".join(part_1)
final_path = part_2 + "/mainfolder/" + [HereYaGo] + "/"
webbrowser.open(final_path)
return