· 8 years ago · Aug 21, 2018, 02:54 PM
1fc = r"C:datafeatureclass"
2flist = arcpy.ListFields(fc)
3for f in flist:
4 name = str(f.name)
5 print name
6 arcpy.AddIndex_management (fc, f , "inx_" + name, "NON_UNIQUE", "NON_ASCENDING")
7
8arcpy.AddIndex_management (fc, f , "inx_" + name, "NON_UNIQUE", "NON_ASCENDING")
9
10arcpy.AddIndex_management (fc, f.name , "inx_" + name, "NON_UNIQUE", "NON_ASCENDING")
11
12fc = r"C:datafeatureclass"
13flist = arcpy.ListFields(fc)
14for f in flist:
15 name = str(f.name)
16 if name == "OBJECTID":
17 print "no oid"
18 elif name == "GlobalID":
19 print "no guid"
20 elif name == "SHAPE":
21 print "no shape"
22 else:
23 arcpy.AddIndex_management (fc, name , "inx_" + name, "NON_UNIQUE", "NON_ASCENDING")
24
25import arcpy,csv,os
26
27#### Connection to FGDB
28FGDB = r"C:***.gdb"
29
30#### Leaving the variable the same but using an SDE connection
31##FGDB = r"C:**Connection to *.sde"
32
33arcpy.env.workspace = FGDB
34
35## Path to csv file
36csvExportFolder = "C:\*\*\*.csv"
37
38## Set to write csv file
39csvFile = csv.writer(open(csvExportFolder,"wb"),delimiter = ",")
40
41###########################################################################################################
42###########################################################################################################
43## Get list of columns from feature classes in a Datasets
44datasets = arcpy.ListDatasets(feature_type='feature')
45
46for ds in datasets:
47## List feature class in datasets
48 for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
49 path = os.path.join(arcpy.env.workspace, ds, fc)
50## List fields in feature class
51 fields = arcpy.ListFields("%(path)s" % vars())
52## Loop through fields
53 for field in fields:
54 colmm = ("{0}".format(field.name))
55 columns = FGDB + ',' + ("%(ds)s" % vars()) + ',' + ("%(fc)s" % vars()) + ',' + ("%(colmm)s" % vars())
56 csvFile.writerow([FGDB,("%(ds)s" % vars()),("%(fc)s" % vars()),("%(colmm)s" % vars())])
57 print ("%(columns)s" % vars())
58
59###########################################################################################################
60###########################################################################################################
61## Get list of columns from feature classes
62FCs = arcpy.ListFeatureClasses()
63
64## Loop through feature classes in list
65for FC in FCs:
66 pathandtable = FGDB + '\' + ("%(FC)s" % vars())
67## print pathandtable
68
69## List fields in feature class
70 fields = arcpy.ListFields("%(pathandtable)s" % vars())
71## Loop through fields
72 for field in fields:
73 colmm = ("{0}".format(field.name))
74 columns = FGDB + ',' + ("%(FC)s" % vars()) + ',' + ("%(colmm)s" % vars())
75 csvFile.writerow([FGDB,"FC",("%(FC)s" % vars()),("%(colmm)s" % vars())])
76 print ("%(columns)s" % vars())
77
78###########################################################################################################
79###########################################################################################################
80##Get list of columns from tables
81tables = arcpy.ListTables()
82
83## Loop through tables in list
84for table in tables:
85## print table
86 pathandtable = FGDB + '\' + ("%(table)s" % vars())
87## print pathandtable
88
89## List fields in tables
90 fields = arcpy.ListFields("%(pathandtable)s" % vars())
91## Loop through fields
92 for field in fields:
93 colmm = ("{0}".format(field.name))
94## print ("%(colmm)s" % vars())
95 columns = FGDB + ',' + ("%(table)s" % vars()) + ',' + ("%(colmm)s" % vars())
96 csvFile.writerow([FGDB,"Table",("%(table)s" % vars()),("%(colmm)s" % vars())])
97 print ("%(columns)s" % vars())
98
99import arcpy,csv,os,time
100
101PathFGDB = "C:\*\ *"
102FGDB_name = "*.gdb"
103DDash = "\"
104CSVFile = "*.csv"
105
106WorkSpace = PathFGDB + DDash + FGDB_name
107arcpy.env.workspace = WorkSpace
108
109csvExportFolder = PathFGDB + DDash + CSVFile
110
111e = 0
112max_rows = sum(1 for line in open("%(csvExportFolder)s" % vars ()))
113print max_rows
114
115with open(("%(csvExportFolder)s" % vars()), 'rb') as f:
116 reader = csv.reader(f)
117 for line in reader:
118 ##print line
119 DS1 = line[1];FC1 = line[2];CNme = line[3];INme = line[4]
120## print ("This is the Feature Class = %(FC1)s" % vars())
121## print ("This is the Column Name = %(CNme)s" % vars())
122## print ("This is the Index Name = %(INme)s" % vars())
123 # Create index
124 if DS1 == "FC" or DS1 == "Table":
125 pathTB = PathFGDB + DDash + FGDB_name + DDash + ("%(FC1)s" % vars())
126 else:
127 pathTB = PathFGDB + DDash + FGDB_name + DDash + ("%(DS1)s" % vars()) + DDash + ("%(FC1)s" % vars())
128 ##print pathTB
129 x = []
130 indexes = arcpy.ListIndexes("%(pathTB)s" % vars())
131 for index in indexes:
132 pa2 = (format(index.name)); ##print pa2
133 x.extend([("%(pa2)s" % vars())])
134 indnam = ["OBJECTID","SHAPE"]
135 indexlist = (x); ##print indexlist
136 if (pa2 <> indnam):
137 if any(INme in s for s in indexlist):
138 e += 1; l = max_rows - e
139 print ("EXISTS row %(e)s of %(max_rows)s rows and %(l)s rows left FC = %(FC1)s and Column = %(INme)s" % vars())
140 else:
141 e += 1; l = max_rows - e
142 print ("NOT EXIST row %(e)s of %(max_rows)s rows and %(l)s rows left FC = %(FC1)s and Column = %(INme)s" % vars())
143 ### "NON_UNIQUE", "NON_ASCENDING" "UNIQUE", "ASCENDING"
144 arcpy.AddIndex_management(pathTB, ("%(CNme)s" % vars()), ("%(INme)s" % vars()), "UNIQUE", "ASCENDING")
145 else:
146 # No more lines to be read from file
147 print ("No more indexs to create")