import arcpy, os from arcpy import env HomeDir = "c:/Data/Path to dataset.." db = "MyData.gdb" InputData = os.path.join(HomeDir, db) env.workspace = InputData
Thank you for the excellent clarification rdharles3.) We also have a path set to where the the python installlation isDo you have this set with the PYTHONPATH environmental variable?
rdharles:In your sample code you use the method getcwd. I am reading that this method returns the current working directory of a process. So in this case, would the working directory be the folder location where the python script is being run from? If this is not the case, what would the working directory be if I see no directory specified in your code?
import arcpy, os log = open("list.txt","a") arcpy.env.workspace = os.getcwd() # For each ws, print the fc's and tbl's. for ws in arcpy.ListWorkspaces("*", "FileGDB"): arcpy.env.workspace = ws # feature classes for fc in arcpy.ListFeatureClasses(): print "fc: "+fc log.write("fc: "+fc+"\n") # tables for tbl in arcpy.ListTables(): print "tbl: "+tbl log.write("tbl: "+tbl+"\n") # feature classes in datasets for ds in arcpy.ListDatasets(): print "ds: "+ds log.write("ds: "+ds+"\n") for dfc in arcpy.ListFeatureClasses("*", "All", ds): print "fc in ds: "+dfc log.write("fc in ds: "+dfc+"\n")
Would ListDatasets help you out?In 1 script where I need to access feature classes inside feature datasets, I loop through the feature datasets and then I loop through the feature classes inside the feature dataset that has the current focus.
import os import arcpy mxd = mxd = arcpy.mapping.MapDocument('current') layer = arcpy.mapping.ListLayers(mxd, 'some_layer')[0] describe = arcpy.Describe(os.path.dirname(layer.dataSource)) ws_type = describe.dataElementType if ws_type == 'DEFeatureDataset': print('is in dataset') elif ws_type == 'DEWorkspace': print('is not in dataset') else: print('unknown datatype') pass
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.