I'm working on a script to automate the conversion of CAD .dwgs of rooms to feature classes, I'm nearing completion and am now working on the second portion of the script (I've seperated it into two modules as the first part takes about an hour to run and the second part should execute MUCH faster). Part of the script involves adding two fields to one layer, and then joining it to another layer.

The problem is, when I execute "arcpy.AddJoin_management" the fields I added aren't in the attribute table. Whats puzzeling is the fields show up when I crate a shapefile from the layer when I perform "arcpy.CopyFeatures_management" before I execute the join.

import arcpy
from arcpy import env
import os
import math

# Set the MTolerance to 0.02
arcpy.env.MTolerance = 0.02

# Set overwrite option

arcpy.env.overwriteOutput = True

#Set Workspace

arcpy.env.workspace = "in_memory"

#input dataset from part 2
converted_CAD = r"C:\Users\JOE.AWESOME\test_script_output\test.shp"

#create a minimum boundary geometry
arcpy.MinimumBoundingGeometry_management (converted_CAD, 'bounding_geom', 'RECTANGLE_BY_AREA','', '', 'MBG_FIELDS')

#create layers for an attribute join
arcpy.MakeFeatureLayer_management (converted_CAD, 'CAD_layer')
arcpy.MakeFeatureLayer_management ('bounding_geom', 'bounding_geom_layer')

#Add a field to the table for the difference between the Minimum Bounding Geometry and the CAD_layer area

arcpy.AddField_management ('CAD_layer', 'area_diffe', 'FLOAT')

arcpy.AddField_management ('CAD_layer', 'area_sqM', 'FLOAT')

#join the two layers for analysis

arcpy.AddJoin_management ('CAD_layer', 'FID', 'bounding_geom_layer', 'ORIG_FID')

#calculate the area of the polygons in the CAD_layer

arcpy.CalculateField_management ('CAD_layer', 'area_sqM', '!shape.area@squaremeters!', 'PYTHON_9.3')

arcpy.CopyFeatures_management ('CAD_layer', r"C:\Users\JOE.AWESOME\test_script_output\join_test.shp")

I've tried changing them to a FLOAT from a DOUBLE, but that didn't change anything. I'm stuck, maybe it's something little. In the words of Michael Bolton, "I always miss some mundane detail."


First step, try inserting an arcpy ListFields function right before the AddJoin. That should verify to you whether the fields you just added are being noticed by ArcPy in the workflow.

I know you said the added fields show up in the attribute table if you save as a shapefile right before performing the join, but i'm curious b/c I had a very similar automated join operation where I had to save the fc before performing the join if I remember correctly. http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000001p000000

  • Ok, so I added the ListFields and I was wrong in stating the fields are being deleted, there are the same number of fields when I execute ListFields as when I execute the Join. They are; however, being renamed when export them to a feature class. This I can work around, but what is the reason for this? – Pete Aug 29 '13 at 20:41
  • 1
    Two reasons I can think of: Your table already has a field with the same name or the added fields' names are reserved names such as "Time". Try joining the table manually in ArcGIS to see if it gives you any complaints. – User73516 Aug 29 '13 at 20:45
  • The names don't change when I do a manual join, instead of fixing this problem I've just located what field corresponds to the name I want and will just go with that. So, I think I'll call this question answered. Thanks for the help! – Pete Aug 30 '13 at 13:14
  • Awesome, glad to help problem solve. – User73516 Aug 30 '13 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.