Tryin to export a Sde to a Gdb with python

138
2
Jump to solution
10-03-2022 06:17 AM
danielROUFFART1
New Contributor II

Hi ! i try to export my Sde to a Gdb with python to ave all of my workevery week, so i have write a script for that

my script is like that:

# -*- coding: utf-8 -*-
import pandas as pd
import os
import glob
import arcpy
import time

arcpy.env.overwriteOutput = True

print ("demarrage programme sauvegarde")


start = time.time()
#Script de Daniel ROUFFART le 29/06/2022
#############################################################################################################
# Sauvegarde Sde

#etape1 liste des Sde
#Cad = "\\CAD@geom06.sde"
Dev = "\\DEV@geom06.sde"
#DICT = "\\DICT@geom06.sde"
#Geo = "\\GEO@geom06.sde"
Gouv = "\\GOUV@geom06.sde"
Mob = "\\MOB@geom06.sde"
#Nav = "\\NAV@geom06.sde"
#Obs = "\\OBS@geom06.sde"
#Rezo = "\\REZO@geom06.sde"
#Topo = "\\Topo@geom06.sde"
#Urba = "\\URBA@geom06.sde"
Rezo_h = "\\Rezo_h@geom06.sde"
Test = "\\TEST@geom06.sde"



gdb = r"C:\representation_parcelaire\DEV.gdb"
arcpy.env.workspace = gdb

fcs = arcpy.ListFeatureClasses("*")
print ("suppression des couches")
for filename in fcs:
    arcpy.Delete_management(filename)







###########################################################################################################


#definition de la source de connexion aux bases Sde
targetPattern=r"C:\\Users\\**\\AppData\\Roaming\\Esri\\ArcGISPro\\Favorites"
target = glob.glob(targetPattern)
print (target)


joiend = [target,Rezo_h]

for ready in joiend:
    # JOIN TARGET
    ready = (''.join([''.join(target),r'\\Rezo_h@geom06.sde']))

print (ready)

# Set environment settings
#arcpy.env.workspace = ready
arcpy.env.workspace = ready

fcs = arcpy.ListFeatureClasses("*")

print (fcs)


#Sauvegarde de la base sde sur une gdb

arcpy.env.workspace = ready
row = r"C:\representation_parcelaire\DEV.gdb"
#fonction sauvegarde des tables
fct = arcpy.ListTables("*")
print (fct)
#verif le cas ou fct = 0
#with arcpy.EnvManager(transferDomains="TRANSFER_DOMAINS"):
#    arcpy.conversion.TableToGeodatabase(fct,row)

#fonction sauvegarde des couches
with arcpy.EnvManager(transferDomains="TRANSFER_DOMAINS"):
    arcpy.FeatureClassToGeodatabase_conversion(fcs,row)

# sauvegarde des     jeux de classe dentitées si besoin

fcd = arcpy.ListDatasets("*","ALL")
print ("fcd")
print (fcd)
for i in fcd:
    outfc = arcpy.ValidateTableName(i)
    print("outfc")
    print (outfc)
    arcpy.management.CreateFeatureDataset(row,outfc)


    fct4 = arcpy.ListTables("*")
    fcs4 = arcpy.ListFeatureClasses("*")
    print("fcs4")
    print (fcs4)
    print("fct4")
    print(fct4)
    row4 = [row +"\\"+i]
    print("row4")
    print(row4)
    for row5 in row4:
        print("row5")
        print(row5)
        arcpy.env.workspace = i
        for sub in fcs4:
            flds = str(sub)
            with arcpy.EnvManager(transferDomains="TRANSFER_DOMAINS"):
                arcpy.conversion.FeatureClassToFeatureClass(sub, row5, flds)

 but when i execute the script i've got this error message.

Traceback (most recent call last):
  File "C:/Users/d.rouffart/Desktop/script Py/Sauvegarde_sde.py", line 118, in <module>
    arcpy.conversion.FeatureClassToFeatureClass(sub, row5, flds)
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\conversion.py", line 2275, in FeatureClassToFeatureClass
    raise e
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\conversion.py", line 2272, in FeatureClassToFeatureClass
    retval = convertArcObjectToPythonObject(gp.FeatureClassToFeatureClass_conversion(*gp_fixargs((in_features, out_path, out_name, where_clause, field_mapping, config_keyword), True)))
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 511, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Échec de l’exécution. Les paramètres ne sont pas valides.
ERROR 000732: Entités en entrée: Dataset rezo_h.geom04.reseaux_InterventionsRegie does not exist or is not supported
ERROR 000732: Emplacement en sortie: Dataset C:\representation_parcelaire\DEV.gdb\rezo_h.geom04.REGIE_EAUX_USEES does not exist or is not supported
Échec de l’exécution de (FeatureClassToFeatureClass).

 

I don't understand why i've got this message can you help me to solve my proble.

 

Thanks

0 Kudos
1 Solution

Accepted Solutions
DonMorrison1
Occasional Contributor III

I suspect you can not have a period in the feature class name in a file geodatabase. Can you change them to underscores? Or maybe just used the last portion of it (REGIE_EAUX_USEES)?

DEV.gdb\rezo_h.geom04.REGIE_EAUX_USEES

 

View solution in original post

0 Kudos
2 Replies
DonMorrison1
Occasional Contributor III

I suspect you can not have a period in the feature class name in a file geodatabase. Can you change them to underscores? Or maybe just used the last portion of it (REGIE_EAUX_USEES)?

DEV.gdb\rezo_h.geom04.REGIE_EAUX_USEES

 

0 Kudos
danielROUFFART1
New Contributor II
effectively te gdb don't accept de point so now it work with the underscore
0 Kudos