When you say "toolbox commands", are you talking about the exact name of the tool (with proper capitalization)?
for newToolName in arcpy.ListTools(): print newToolName
# # Updates Tools, Functions, Environments & a few Methods from 9.x to "case-sensitive" 10.x # # Note: Rewrites script(s) to hardcoded "ARC10" directory. # # Thoughts: # Can I get a list of all Methods & Properties? # # R.D. Harles # 11-21-10 # import arcpy, os, sys, string # Output directory for updated scripts if not os.path.exists("ARC10"): os.mkdir("ARC10") # Create the master dictionary masterDict={} # Add tools to the masterDict (with and without the toolbox) # Note: The "(" is required because some tools start with the same word as others (e.g. gp.select & gp.selectlayerbylocation) for newToolName in arcpy.ListTools(): # Without toolbox (e.g. clip) masterDict["gp."+newToolName.split("_")[0].lower()+"("] = "arcpy."+newToolName+"(" # With toolbox (e.g. clip_management) masterDict["gp."+newToolName.lower()+"("] = "arcpy."+newToolName+"(" # Add environments to the masterDict for env in arcpy.ListEnvironments(): masterDict["gp."+env.lower()] = "arcpy.env."+env # These don't get listed for some reason? masterDict["gp.overwriteoutput"] = "arcpy.env.overwriteOutput" masterDict["gp.GetParameterAsText"] = "arcpy.env.GetParameterAsText" # Add functions to the masterDict functions = ["AddError","AddFieldDelimiters","AddIDMessage","AddMessage","AddReturnMessage","AddToolbox","AddWarning", "AsShape","CheckExtension","CheckInExtension","CheckOutExtension","CheckProduct","ClearEnvironment", "Command","CopyParameter","CreateObject","CreateRandomValueGenerator","CreateScratchName","CreateUniqueName", "Describe","Exists","GetArgumentCount","GetIDMessage","GetInstallIInfo","GetMaxSeverity","GetMessage", "GetMessageCount","GetMessages","GetParameter","GetParameterAsText","GetParameterCount","GetParameterInfo", "GetParameterValue","GetReturnCode","GetSeverity","GetSeverityLevel","GetSystemEnvironment","ImportToolbox", "InsertCursor","IsSynchronous","ListDatasets","ListEnvironments","ListFeatureClasses","ListFields","ListFiles", "ListIndexes","ListInstallations","ListPrinterNames","ListRasters","ListTables","ListToolboxes","ListTools", "ListVersions","ListWorkspaces","LoadSettings","NumpyArrayToRaster","ParseFieldName","ParseTableName", "ProductInfo","RasterToNumPyArray","RefreshActiveView","RefreshCatalog","RefreshTOC","RemoveToolbox", "ResetEnvironments","ResetProgressor","SaveSettings","SearchCursor","SetParameter","SetParameterAsText", "SetProduct","SetProgressor","SetProgressorLabel","SetProgressorPosition","SetSeverityLevel","TestSchemaLock", "UpdateCursor","Usage","ValidateFieldName","ValidateTableName"] for func in functions: masterDict["gp."+func.lower()] = "arcpy."+func # Add cursor methods to masterDict methods = ["next","reset","newRow","insertRow","updateRow","deleteRow","getValue","isNull","setNull","setValue","getPart","getObject","removeAll","partCount"] for meth in methods: masterDict[meth.lower()] = meth # This isn't going to work. There could be up to 3 replaceable items on one line and only item item per line can be replace the way the script is written. ### Codes and return values ##codesReturnValues = ["ArcView","ArcEditor","ArcInfo","Engine","EngineGeoDB","ArcServer","AlreadyInitalized","Available","Unavailable","NotLicensed","Failed"] ##for crv in codesReturnValues: ## masterDict[crv.lower()] = crv # Add misc to masterDict masterDict["gp = arcgisscripting.create()"] = "" masterDict["gp = arcgisscripting.create(9.3)"] = "" # Loop through python scripts for script in os.listdir(''): if script.endswith('.py'): print "\nProcessing "+script+"..." # Open new file (output to hardcoded "ARC10" directory) wfile = open("ARC10/"+script, "w") count=0 # Read existing script (line by line) for line in open(script).readlines(): # Make the line lower case to ensure match with lower case item lower = line.lower() count=count+1 # Loop through master dictionary for item in masterDict: # Get the key (2nd part of the pair) key = masterDict[item] # Check for a match in the line x = lower.find(item) # Continue if there is a match if x != -1: # Do the search & replace fix = lower.replace(item, key) # Write it (changed line) wfile.write(fix) print " "+script+": (line"+str(count)+") Replacing '"+item+"' with '"+key+"'" break if x == -1: # Write it (unchanged line) wfile.write(line) print " "+script+": (line"+str(count)+") Writing original line: "+line # Close file wfile.close() ## Replace arcgisscripting with arcpy # Open file in read mode file = open("ARC10/"+script, "r") # Read entire file text = file.read() # Closes the read session file.close() file = open("ARC10/"+script, "w") print "\n ...Replacing arcgisscripting with arcpy" file.write(text.replace("arcgisscripting", "arcpy")) file.close() print "\nDone.\n"
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.