2

i´ve built in a tool for arccatalog which transfers GIS Files into shape Files. Everything is working so far, but i want it a bit more customer friendly.

Atm it looks like this:

You can right click on the file (here MapInfo .tab file) in the catalog tree and choose in the context menu "Konvertierung in WGS 1984"

enter image description here

then the tool interface opens and you can choose your input and output file:

enter image description here

But its annoying to choose all the time the input in the file system again. I want that my selected file from the catalog tree is already listed as input data.

So my question is:

Is there any way to set the workspace from the input data in my tool TO the selected file on which i right clicked (here: Blk1403.Tab), i.e. the Filepath which is listed on the top in arccatalog.

enter image description here

The Tool is just a simple Model built with ModelBuilder, it contains some Py scripts and some tools from the Toolbox. Then the Model is implemented as a Button with the Add-in Wizard. Then it is draged & dropped into the context menu of the "Text-contextmenu" via Customize Mode.

The first py script of the Model calls the ogr2ogr.exe and looks so far right now:

# -*- coding: iso-8859-15 -*-

import sys
import string
import os
import arcgisscripting
import arcpy

gp = arcgisscripting.create()

inPath1 = sys.argv[1]

outformat = sys.argv[2]
outPath1 = sys.argv[3]


ogrstring = ' -f "' + outformat + '" "' + outPath1 + '" "' + inPath1 + '""' 
callstring = '"C:\\WINDOWS\\system32\\cmd.exe /C" "R:\\RBS\\Software\\FWTools2.4.7\\bin\\ogr2ogr.exe" ' + ogrstring

gp.addmessage(callstring)

os.system(callstring)
  • 2
    How were the context menu items implemented? Also I don't believe this is possible without using ArcObjects. – blah238 Jun 20 '14 at 20:42
  • The context menu is implemented via Customize -> Customize Mode -> Edit "Text Contextmenu" in the Toolbar "Context menu" – Christian Langer Jun 23 '14 at 9:18
1

I am assuming you want to change the directory based off the file selected in the dialog, correct?

Try something like this:

shapefile = arcpy.GetParameterAsText(0) #whatever index it is
directory = os.path.dirname(shapefile) #pull the directory from the shapefile
arcpy.env.workspace = directory #set the arcpy workspace to the directory

That should work for you if you are assigning the shapefile in the dialog box. If that isn't correct, give me a better explanation of your work flow, and I might be able to help more.

  • 2
    He wants to have the file he right clicks on to automatically populate into the tool he selects. – ianbroad Jun 20 '14 at 17:59
  • Hmm. Well, then you might be able to do the same thing I was doing without the GetParameterAsText. If there is somewhere in the script where you have access to the file itself (in this case .Tab) you should be able to do a directory call on it and then change the workspace before any work is done. – Branco Jun 20 '14 at 18:02
  • Cheers Ian, this is exactly what I plan to do! I want that my selected file on which I right click with the mouse is listed automatically as my input file in my tool! – Christian Langer Jun 23 '14 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.