Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Copyfeatures_management with joined table Q

$
0
0
I need some help on a script that i am putting together.
Script is as follows.

1. Select feature
2. Export the selected feature
3. Load the export feature
4. Label the feature

I have a shapefile with a joined table in Arcmap. The script runs fine until it gets to the labeling part. I get back Acres filed does not exist to lable. I check the "NewFeatures" layer and i noticed that the attributes fields names were named after the feature class name like vector_D_3, Vector_D4, etc.. and not the actual tables names.

I have attached a picture of what the tables looks after the copyfeatures_management.

Here is my code.
Code:

import arcpy,os, sys
import arcpy.mapping
# Set workspace
arcpy.env.workspace = "C:/Temp"
arcpy.env.overwriteOutput = 'True'

directory="C:/Temp/Split.pdf"
if os.path.exists(directory):
    try:
        os.remove(directory)
    except:
        print "Exception: ",str(sys.exc_info())
else:
    print 'File not found at ',directory

#arcpy.RefreshActiveView()

mxd = arcpy.mapping.MapDocument("current")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "TaxParcels")[0]
df.extent = lyr.getSelectedExtent()
df.scale = 5000

if int(arcpy.GetCount_management("TaxParcels").getOutput(0)) > 0:
 

    #arcpy.CopyFeatures_management("TaxParcels", "C:/temp/NewFeatures.shp")
    arcpy.Select_analysis("TaxParcels", "C:/temp/NewFeatures.shp")

#Adding Labels
layer = arcpy.mapping.ListLayers(mxd, "NewFeatures")[0]
if layer.supports("LABELCLASSES"):
    for lblclass in layer.labelClasses:
        lblclass.className = "vector_D_1" #This should be Account
        lblclass.expression = "[vector_D_1] & VBNewLine & Round([vector_D_5],2)" #these should be "ACCOUNT" & "ACRES"
    lblclass.showClassLabels = True
layer.showLabels = True

arcpy.RefreshActiveView()

arcpy.mapping.ExportToPDF(mxd,"C:/Temp/Split.pdf", "")

Attached Thumbnails
Click image for larger version

Name:	Image1.png‎
Views:	N/A
Size:	15.0 KB
ID:	21178  

Viewing all articles
Browse latest Browse all 2485

Trending Articles