1

I have some code that will take a ArcGIS 10.2.2 feature class and post a copy of it in a different geodatabase.

My code is set up so the end user can pick the feature class they want the model to run (getparameterastext). My problem is the code doesn't name the new feature class the same name as the original feature class. My code "hard codes" a name to the new feature class being posted. What do I need to change the my code so the new file will name the new feature class the same name of the original feature class the end user pics? This is what my code looks like.

# Import arcpy module
import arcpy
# Local variables:
maint_FC = arcpy.GetParameterAsText(0)
sdr_staging_gdb = "Y:\\data\\dev\\staging\\sdr_staging.gdb"
staging = "Y:\\data\\dev\\staging"
# Process: Feature Class to Feature Class
arcpy.FeatureClassToFeatureClass_conversion(maint_FC, sdr_staging_gdb, 'maint_FC', "", "POL_DIST \"POL_DIST\" true true false 3 Text 0 0 ,First,#,Database Connections\\UGGSSSQL_GISPUB_basemap.sde\\gispub.BASEMAP.gisdata\\gispub.BASEMAP.TL_TEST_2,POL_DIST,-1,-1;INSPECTOR \"INSPECTOR\" true true false 50 Text 0 0 ,First,#,Database Connections\\UGGSSSQL_GISPUB_basemap.sde\\gispub.BASEMAP.gisdata\\gispub.BASEMAP.TL_TEST_2,INSPECTOR,-1,-1;INSP_NBR \"INSP_NBR\" true true false 3 Text 0 0 ,First,#,Database Connections\\UGGSSSQL_GISPUB_basemap.sde\\gispub.BASEMAP.gisdata\\gispub.BASEMAP.TL_TEST_2,INSP_NBR,-1,-1;COMMENT \"COMMENT\" true true false 50 Text 0 0 ,First,#,Database Connections\\UGGSSSQL_GISPUB_basemap.sde\\gispub.BASEMAP.gisdata\\gispub.BASEMAP.TL_TEST_2,COMMENT,-1,-1;DATE_MOD \"DATE_MOD\" true true false 36 Date 0 0 ,First,#,Database Connections\\UGGSSSQL_GISPUB_basemap.sde\\gispub.BASEMAP.gisdata\\gispub.BASEMAP.TL_TEST_2,DATE_MOD,-1,-1;DATE_ADDED \"DATE_ADDED\" true true false 36 Date 0 0 ,First,#,Database Connections\\UGGSSSQL_GISPUB_basemap.sde\\gispub.BASEMAP.gisdata\\gispub.BASEMAP.TL_TEST_2,DATE_ADDED,-1,-1;MOD_BY \"MOD_BY\" true true false 50 Text 0 0 ,First,#,Database Connections\\UGGSSSQL_GISPUB_basemap.sde\\gispub.BASEMAP.gisdata\\gispub.BASEMAP.TL_TEST_2,MOD_BY,-1,-1;ADDED_BY \"ADDED_BY\" true true false 50 Text 0 0 ,First,#,Database Connections\\UGGSSSQL_GISPUB_basemap.sde\\gispub.BASEMAP.gisdata\\gispub.BASEMAP.TL_TEST_2,ADDED_BY,-1,-1;Shape_STArea__ \"Shape_STArea__\" false false true 0 Double 0 0 ,First,#,Database Connections\\UGGSSSQL_GISPUB_basemap.sde\\gispub.BASEMAP.gisdata\\gispub.BASEMAP.TL_TEST_2,Shape.STArea(),-1,-1;Shape_STLength__ \"Shape_STLength__\" false false true 0 Double 0 0 ,First,#,Database Connections\\UGGSSSQL_GISPUB_basemap.sde\\gispub.BASEMAP.gisdata\\gispub.BASEMAP.TL_TEST_2,Shape.STLength(),-1,-1", "")
# Process: Feature Class To Shapefile (multiple)
arcpy.FeatureClassToShapefile_conversion(maint_FC, staging)
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Sep 30, 2015 at 14:52

1 Answer 1

2

You could use the Describe function to grab the name or basename of the feature class, and use it for the output name.

import arcpy
maint_FC = arcpy.GetParameterAsText(0)
workspace_type = str(arcpy.Describe(arcpy.Describe(maint_FC).path).workspaceFactoryProgID)
if workspace_type == "esriDataSourcesGDB.SdeWorkspaceFactory.1":
 maint_FC_name = str(arcpy.Describe(maint_FC).baseName).split(".")[-1]
else:
 maint_FC_name = str(arcpy.Describe(maint_FC).baseName)
sdr_staging_gdb = "Y:\\data\\dev\\staging\\sdr_staging.gdb"
arcpy.FeatureClassToFeatureClass_conversion(maint_FC, sdr_staging_gdb, maint_FC_name, "#", "#")
answered Sep 30, 2015 at 15:38
6
  • The code works fine. It just names the new feature class "maint_FC". I want the code to call the feature class the same name as the one picked by the end user. Commented Sep 30, 2015 at 15:44
  • @Nebula93 well that's what this should do, good luck. Commented Sep 30, 2015 at 15:49
  • That didn't work....It just named the file "maint_FC_name"....thanks for the help though! Commented Sep 30, 2015 at 16:19
  • @Nebula93 then you must have put quotes around "maint_FC_name". It should be exactly how I have it in my example. There shouldn't be any quotes, it should just say maint_FC_name because it's a variable. Commented Sep 30, 2015 at 16:20
  • 1
    @Nebula93 it looks like you're copying data from SDE to a file geodatabase. In SDE the feature class is named GISMAINT.GIS_OWNER.April_Test1 which is not a valid name. I assume you just want April_Test1 as the output name? I've edited the code in my answer. Commented Sep 30, 2015 at 17:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.