Scripts/ExportGems.pyt
def execute(self, parameters, messages):
        """The source code of the tool."""
        databaseConnection = parameters[0].valueAsText
        targetGDB = parameters[1].valueAsText
        replicateDatabase(databaseConnection, targetGDB, messages)

        #Set workspace
        arcpy.env.workspace = targetGDB

        #feature classes in feature datasets
        #TODO: Do we care about feature datasets other than GeologicMap?
        featureDatasets = arcpy.ListDatasets(feature_type="Feature")
        for fd in featureDatasets: #loop through each feature class
            messages.addMessage("fd = " + fd);
            featureClasses = arcpy.ListFeatureClasses(feature_dataset=fd)
            for fc in featureClasses: #loop through each feature class
                fc = targetGDB + "\\" + fc
                messages.addMessage("fc = " + fc);          
                fieldList = arcpy.ListFields(fc)  #get a list of fields for each feature class
                for field in fieldList: #loop through each field
                    messages.addMessage("field = " + field.name);
                    messages.addMessage("field alias = " + field.aliasName);
                    messages.addMessage("field required = " + str(field.required));
                    if not field.required:
                        try:
                            arcpy.AlterField_management(fc, field.name, field.name + "x") #rename field to tmp val. Lame, but necessary to convince arc that we really do want to rename the field to itself in mixed case.
                            messages.addMessage("tmp rename over");
                            arcpy.AlterField_management(fc, field.name + "x", field.aliasName) #rename field from alias
                            messages.addMessage("alias over");
                        except:
                            messages.addMessage("failed to rename field " + field.name)

        #Standalone feature classes
        #TODO: Do we care about these?
        featureClasses = arcpy.ListFeatureClasses()
        for fc in featureClasses: #loop through each feature class
            fc = targetGDB + "\\" + fc
            messages.addMessage("fc = " + fc);
            fieldList = arcpy.ListFields(fc)  #get a list of fields for each feature class
            for field in fieldList: #loop through each field
                if not field.required:
                    messages.addMessage("field = " + field.name);
                    messages.addMessage("field alias = " + field.aliasName);
                    try:
                        arcpy.AlterField_management(fc, field.name, field.name + "x") #rename field to tmp val
                        arcpy.AlterField_management(fc, field.name + "x", field.aliasName) #rename field from alias
                    except:
                        messages.addMessage("failed to rename field " + field.name)

        tables = arcpy.ListTables()
        for t in tables: #loop through each feature class
            t = targetGDB + "\\" + t
            messages.addMessage("t = " + t);
            fieldList = arcpy.ListFields(t)  #get a list of fields for each feature class
            for field in fieldList: #loop through each field
                if not field.required:
                    messages.addMessage("field = " + field.name);
                    messages.addMessage("field alias = " + field.aliasName);
                    try:
                        arcpy.AlterField_management(t, field.name, field.name + "x") #rename field from alias
                        arcpy.AlterField_management(t, field.name + "x", field.aliasName) #rename field from alias
                    except:
                        messages.addMessage("failed to rename field " + field.name)
        
        return
The source code of the tool.
The source code of the tool.
The source code of the tool .
def execute(self, parameters, messages):
        databaseConnection = parameters[0].valueAsText
        targetGDB = parameters[1].valueAsText
        replicateDatabase(databaseConnection, targetGDB, messages)
        arcpy.env.workspace = targetGDB
        featureDatasets = arcpy.ListDatasets(feature_type="Feature")
        for fd in featureDatasets: 
            messages.addMessage("fd = " + fd);
            featureClasses = arcpy.ListFeatureClasses(feature_dataset=fd)
            for fc in featureClasses: 
                fc = targetGDB + "\\" + fc
                messages.addMessage("fc = " + fc);          
                fieldList = arcpy.ListFields(fc)  
                for field in fieldList: 
                    messages.addMessage("field = " + field.name);
                    messages.addMessage("field alias = " + field.aliasName);
                    messages.addMessage("field required = " + str(field.required));
                    if not field.required:
                        try:
                            arcpy.AlterField_management(fc, field.name, field.name + "x") 
                            messages.addMessage("tmp rename over");
                            arcpy.AlterField_management(fc, field.name + "x", field.aliasName) 
                            messages.addMessage("alias over");
                        except:
                            messages.addMessage("failed to rename field " + field.name)
        featureClasses = arcpy.ListFeatureClasses()
        for fc in featureClasses: 
            fc = targetGDB + "\\" + fc
            messages.addMessage("fc = " + fc);
            fieldList = arcpy.ListFields(fc)  
            for field in fieldList: 
                if not field.required:
                    messages.addMessage("field = " + field.name);
                    messages.addMessage("field alias = " + field.aliasName);
                    try:
                        arcpy.AlterField_management(fc, field.name, field.name + "x") 
                        arcpy.AlterField_management(fc, field.name + "x", field.aliasName) 
                    except:
                        messages.addMessage("failed to rename field " + field.name)
        tables = arcpy.ListTables()
        for t in tables: 
            t = targetGDB + "\\" + t
            messages.addMessage("t = " + t);
            fieldList = arcpy.ListFields(t)  
            for field in fieldList: 
                if not field.required:
                    messages.addMessage("field = " + field.name);
                    messages.addMessage("field alias = " + field.aliasName);
                    try:
                        arcpy.AlterField_management(t, field.name, field.name + "x") 
                        arcpy.AlterField_management(t, field.name + "x", field.aliasName) 
                    except:
                        messages.addMessage("failed to rename field " + field.name)
        return
def execute ( self , parameters , messages ) : databaseConnection = parameters [ 0 ] . valueAsText targetGDB = parameters [ 1 ] . valueAsText replicateDatabase ( databaseConnection , targetGDB , messages ) arcpy . env . workspace = targetGDB featureDatasets = arcpy . ListDatasets ( feature_type = "Feature" ) for fd in featureDatasets : messages . addMessage ( "fd = " + fd ) ; featureClasses = arcpy . ListFeatureClasses ( feature_dataset = fd ) for fc in featureClasses : fc = targetGDB + "\\" + fc messages . addMessage ( "fc = " + fc ) ; fieldList = arcpy . ListFields ( fc ) for field in fieldList : messages . addMessage ( "field = " + field . name ) ; messages . addMessage ( "field alias = " + field . aliasName ) ; messages . addMessage ( "field required = " + str ( field . required ) ) ; if not field . required : try : arcpy . AlterField_management ( fc , field . name , field . name + "x" ) messages . addMessage ( "tmp rename over" ) ; arcpy . AlterField_management ( fc , field . name + "x" , field . aliasName ) messages . addMessage ( "alias over" ) ; except : messages . addMessage ( "failed to rename field " + field . name ) featureClasses = arcpy . ListFeatureClasses ( ) for fc in featureClasses : fc = targetGDB + "\\" + fc messages . addMessage ( "fc = " + fc ) ; fieldList = arcpy . ListFields ( fc ) for field in fieldList : if not field . required : messages . addMessage ( "field = " + field . name ) ; messages . addMessage ( "field alias = " + field . aliasName ) ; try : arcpy . AlterField_management ( fc , field . name , field . name + "x" ) arcpy . AlterField_management ( fc , field . name + "x" , field . aliasName ) except : messages . addMessage ( "failed to rename field " + field . name ) tables = arcpy . ListTables ( ) for t in tables : t = targetGDB + "\\" + t messages . addMessage ( "t = " + t ) ; fieldList = arcpy . ListFields ( t ) for field in fieldList : if not field . required : messages . addMessage ( "field = " + field . name ) ; messages . addMessage ( "field alias = " + field . aliasName ) ; try : arcpy . AlterField_management ( t , field . name , field . name + "x" ) arcpy . AlterField_management ( t , field . name + "x" , field . aliasName ) except : messages . addMessage ( "failed to rename field " + field . name ) return
The source code of the tool.
The source code of the tool .
"""The source code of the tool.""" #Set workspace #feature classes in feature datasets #TODO: Do we care about feature datasets other than GeologicMap? #loop through each feature class #loop through each feature class #get a list of fields for each feature class #loop through each field #rename field to tmp val. Lame, but necessary to convince arc that we really do want to rename the field to itself in mixed case. #rename field from alias #Standalone feature classes #TODO: Do we care about these? #loop through each feature class #get a list of fields for each feature class #loop through each field #rename field to tmp val #rename field from alias #loop through each feature class #get a list of fields for each feature class #loop through each field #rename field from alias #rename field from alias
self
parameters
messages