简体   繁体   中英

CAD to Feature Class

import arcpy
fc = r'H:\H-ONUS UTILITY DATA GIS\As_Builts\2014\RandolphPoint_Phase2\789-AS-BUILT 8-7-13.dwg\Polyline'
out_gdb = r'H:\H-ONUS UTILITY DATA GIS\As_Builts\2014\RandolphPoint_Phase2\RandolphPoint.gdb.gdb'
field = 'Layer'
values = [row[0] for row in arcpy.da.SearchCursor(fc, (field))]
uniqueValues = set(Values)

for value in uniqueValues:
    sql = """Layer" = '{0}'""".format(Value)
    name = arcpy.ValidateTableName(value,out_gdb)
    arcpy.FeatureClassToFeatureClass_conversion(fc, out_gdb, name, sql)

I am trying to convert CAD(dwg) to ArcGIS 10.2.2 Feature Classes using a file geodatase as the workspace. I was just taught this code at an ESRI conference and of course it worked beautifully for the insturtor.
My error I am getting is "NameError:name'Values' is not defined" however I did define it as values = [row[0] for row in arcpy.da.SearchCursor(fc, (field))] I have been working hours on this, it would help out my job considerably.

Python variables are case-sensitive.

You've declared values with a lower-case v, but you're referring to it on the next line with an upper-case V.

(Same with value / Value further down.

import arcpy
fc = r'H:\H-ONUS UTILITY DATA GIS\As_Builts\2014\RandolphPoint_Phase2\789ASBUILT.dwg\Polyline'
out_gdb = r'H:\H-ONUS UTILITY DATA GIS\As_Builts\2014\RandolphPoint_Phase2\RandolphPoint.gdb'
field = 'Layer'
value = [row[0] for row in arcpy.da.SearchCursor(fc, (field))]
uniquevalues = set(value)

for value in uniquevalues:
    sql = """"Layer" = '{0}'""".format(value)
    name = arcpy.ValidateTableName(value,out_gdb)
    arcpy.FeatureClassToFeatureClass_conversion(fc, out_gdb, name, sql)

Here is the solution, I had an extra .gdb in the geodatabase path

my word value was values so had to take the s off

and also in my sql statement I was missing a " before the word Layer

If anyone is reading this just change the individual parameters and it works beautifully!

thanks Juffy for responding and trying to help me out

Cartogal

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM