Hi Dear Friends,
How to split the data drawing number wise for all features from mdb or gdb file.
I have 8 types of drawing numbers available in data I want to split each drawing number separate data mdb format or gdb format file.
Thanks
Santhosh
Solved! Go to Solution.
I am assuming that the picture in my last post is generally what you are looking for.
As Dan Patterson mentioned, since the database exists you can't overwrite it. You can delete it with code or just use it. A line of code could be added to check for the existence of the database.
As seen in your attached jpeg, you are getting a second error:
object has no attribute 'SplitByAttributes_analysis'
Split By Attributes was added at version 10.5 and Pro. Since you are at 10.1, we will need a different solution. I would suggest looping through your datasets and features and using Select Layer By Attribute with a where clause, something like:
arcpy.SelectLayerByAttribute_management('FA_Box', 'NEW_SELECTION',
where_clause = "DRAWING_REFERENCE = 'C0500-GS-0117-01-EL-FA-A0-03-001-001'")
If records are selected, then copy them to the appropriate database. Hope this helps.
10.1?! missed that
https://www.arcgis.com/home/item.html?id=15ca63aebb4647a4b07bc94f3d051da5
the original split by attribute... can't remember if it works on that old a version.
but it has the coolest page icon, if I may say so
Since you are using 10.1, I experimented with SelectLayerByAttributes. I found it easiest to code to work with one geodatabase (the one in your zip file). I first ran a script to get a list of the unique attributes used in the DRAWING_REFERENCE fields of all the features in the gdb. Since the drawing reference is rather long, I paired it with a shorter substring. This is what the gdb looks like in catalog:
Each feature is appended with the short substring; in this case, GF is highlighted. Here's the code:
import arcpy
import os
gdb = r'C:\Path\to\COBW_Firealarm.gdb'
arcpy.env.workspace = gdb # needed for ListDatasets
fields = ['DRAWING_REFERENCE']
draw_ref = [ # unique values in DRAWING_REFERENCE fields, name append value
[ '111-111-AP','AP' ],
[ 'C0500-GS-0117-04-EL-FA-A0-01-001-001', '01' ],
[ 'C0500-GS-0117-04-EL-FA-A0-02-001-001', '02' ],
[ 'C0500-GS-0117-01-EL-FA-A0-03-001-001', '03' ],
[ 'C0500-GS-0117-04-EL-FA-A0-04-001-001', '04' ],
[ 'C0500-GS-0117-04-EL-FA-A0-05-001-001', '05' ],
[ 'C0500-GS-0117-04-EL-FA-A0-06-001-001', '06' ],
[ 'C0500-GS-0117-01-EL-FA-A0-B1-001-001', 'B1' ],
[ 'C0500-GS-0117-04-EL-FA-A0-B2-001-001', 'B2' ],
[ 'C0500-GS-0117-04-EL-FA-A0-GF-001-001', 'GF' ]
] # name append keeps feature name from becoming too long
for fds in arcpy.ListDatasets('','Feature'):
print "\nProcessing {}".format(fds)
for fc in arcpy.ListFeatureClasses('','',fds):
print "\t{}".format(fc) # use fc for name of target geodatabase
in_fc = os.path.join(gdb,fds,fc)
if arcpy.Exists('temp_layer'):
arcpy.Delete_management('temp_layer')
arcpy.MakeFeatureLayer_management(in_fc,'temp_layer')
ref_num = 0
for dr in draw_ref: # loop through drawing reference list
# dr[0] = DRAWING_REFERENCE field value
# dr[1] = a substring of DRAWING_REFERENCE used in naming new feature class
arcpy.SelectLayerByAttribute_management('temp_layer',
'NEW_SELECTION',
where_clause = "DRAWING_REFERENCE = '{}'".format(dr[0]))
count = int(arcpy.GetCount_management('temp_layer').getOutput(0))
if count > 0:
ref_num += 1
new_fc = os.path.join(fds, "{}_{}".format(fc,dr[1]))
print "\t\t{} -- count: {}".format(new_fc,count)
# write the selected features to a new featureclass
arcpy.CopyFeatures_management('temp_layer', new_fc)
print "\t\t{} total new features".format(ref_num)
arcpy.Delete_management('temp_layer')
print "\nDone."
For the next steps, you can use a script to loop through the draw_ref list, making a copy the first gdb, deleting the features that don't match the current value in the draw_ref list, and repeat until each drawing reference has its own gdb.
Hope this helps.
Dear Randy Burton,
I really appreciate you for helpling thank you somuch.
Thanks
santhosh