derklauer

better way to write this script?

Discussion created by derklauer on Sep 14, 2012
Latest reply on Sep 14, 2012 by gnewburyiv
Hello, I have a CAD DWG drawing that has layers that I want to export into individual shape files.  I have written my python script and it works but I do not believe it is the most efficient way to write it. My specefic question is I wrote a command line for every layer having an input layer name and an ouput shapefile.  Is there a way to write this so that the script identifies every unique layer name and outputs the shape file without having to write a command for each CAD layer?

# Import arcpy module
import arcpy


# Local variables:
centerline_grid_dwg_Polygon__2_ = "centerline_grid.dwg Group Layer\\centerline_grid.dwg Polygon"
centerline_grid_dwg_Polygon__3_ = "centerline_grid.dwg Group Layer\\centerline_grid.dwg Polygon"
Dan = "C:\\Dan"

# Process: Select Layer By Attribute
arcpy.SelectLayerByAttribute_management(centerline_grid_dwg_Polygon__2_, "NEW_SELECTION", "\"Layer\" = 'segment _1A_Horizontal Control'")

# Process: Feature Class to Feature Class
arcpy.FeatureClassToFeatureClass_conversion(centerline_grid_dwg_Polygon__3_, Dan, "test5556.shp", "", "Entity \"Entity\" true true false 16 Text 0 0 ,First,#,N:\\Inter Departmental Data\\centerline_grid.dwg\\Polygon,Entity,-1,-1;Layer \"Layer\" true true false 255 Text 0 0 ,First,#,N:\\Inter Departmental Data\\centerline_grid.dwg\\Polygon,Layer,-1,-1;Color \"Color\" true true false 2 Short 0 0 ,First,#,N:\\Inter Departmental Data\\centerline_grid.dwg\\Polygon,Color,-1,-1;Linetype \"Linetype\" true true false 255 Text 0 0 ,First,#,N:\\Inter Departmental Data\\centerline_grid.dwg\\Polygon,Linetype,-1,-1;Elevation \"Elevation\" true true false 8 Double 0 0 ,First,#,N:\\Inter Departmental Data\\centerline_grid.dwg\\Polygon,Elevation,-1,-1;LineWt \"LineWt\" true true false 2 Short 0 0 ,First,#,N:\\Inter Departmental Data\\centerline_grid.dwg\\Polygon,LineWt,-1,-1;RefName \"RefName\" true true false 255 Text 0 0 ,First,#,N:\\Inter Departmental Data\\centerline_grid.dwg\\Polygon,RefName,-1,-1", "")


this is a snippet the above two lines are duplicated many more time times changing the query statment to match a new layer name and the output file name....

Outcomes