Invalid Characters in Creating Feature Class

1089
7
02-21-2018 12:37 PM
VishalShah2
Occasional Contributor II

Hello,

In order to do a network analysis without altering the existing data, I am creating a new GDB that will then have the 3 feature classes I need created within and then the data appended to it. However, when I try to create the feature class in my script, I get an error saying invalid characters. I looked up the error but couldn't derive a solution. Any help is greatly appreciated.

Here is my script:

outLocation = copied_Geodatabase
fiberFC = 'Fiber'
fiberTemplate = arcpy.mapping.ListLayers(mxd, 'Fiber Segments')[0]
fiber_geometry = 'POLYLINE'


arcpy.CreateFeatureclass_management(outLocation, fiberFC, fiber_geometry, fiberTemplate)
0 Kudos
7 Replies
JamesMacKay3
Occasional Contributor

That error usually means there's whitespace, a hyphen, something like that in the table name - strange error in this case though since "Fiber" should be valid.  Try using this function to validate your table name:

(Edit: Posted the wrong link in my original post)

ValidateTableName—Help | ArcGIS for Desktop 

VishalShah2
Occasional Contributor II

Hi James, I saw this as a possible solution when I was researching this error before. Question though, do I have to add the validate function within my script for every feature class being created?

0 Kudos
JamesMacKay3
Occasional Contributor

Yes, you'll need to call it for each unique feature class name.  You may also want to have a look at the "Validate Field Name" function, since you're using a template as part of your feature class creation.  You could be pulling in a field that has a name that's valid in one type of workspace but invalid in another - for example, some field names may be valid in a File Geodatabase that aren't valid in SQL Server or in a Shapefile.

0 Kudos
VishalShah2
Occasional Contributor II

James, so I figured out what I was doing wrong. So originally in my script I have a template GDB where that is copied to create another workplace GDB. After that, I attempt to append the data. Originally my tempalte GDB was corrupt and had no data in it and thus I went the step of creating feature classes within the copied GDB, thus this thread being created. However, now that my GDB is not corrupt, I don't have to create new features in the GDB. Thanks for the help!

0 Kudos
JoeBorgione
MVP Esteemed Contributor

The error should tell you which line number in your script has the offending invalid characters.  With that said,it's a little unclear as where you are writing this new feature class.

The 'out_path' argument for this tool is a path to a given workspace for example:

out_path = r'C:\the\path\to\My.gdb'

Perhaps you could include your full script along with the full error?

CreateFeatureclass_management (out_path, out_name, {geometry_type}, {template}, {has_m}, {has_z}, 
{spatial_reference}, {config_keyword}, {spatial_grid_1}, {spatial_grid_2}, {spatial_grid_3})

can't wait to retire....
0 Kudos
VishalShah2
Occasional Contributor II

Hi Joe, so the error said it takes place where I am trying to create the feature class

arcpy.CreateFeatureclass_management(outLocation, fiberFC, fiber_geometry, fiberTemplate)

where outLocation is a geodatabase that is created earlier in my script (this part works). It's the create feature class that is giving me issues. Of course my GDB does not have any spaces.

0 Kudos
JoeBorgione
MVP Esteemed Contributor

Like James mentions your error problem seems weird.  I just ran the same basic thing in a python window in ArcMap with a couple of tweeks and it worked for me...

For out_name I used a single quoted name instead of a variable :  'NewFeatureClass'

For template I didn't use a layer from the listLayers as you did, but rather set a variable to an actual path:

out_location = r'C:\users\JBorgione\Test.gdb'

arcpy.CreateFeatureclass_management(out_location,'NewFeatureCass',fc_geometry,fcTemplate)‍‍
can't wait to retire....