Here's the full code, though it's evolved a bit since the original post.For the sake of brevity, I'm not posting the entire code here. Just the section causing issues but I do know for a fact that the issue is within the section. I'm also just using the 'cbsaFD' variable statically for testing purposes however, in the actual code 'cbsaFD' represents an list item to iterate through using a for-loop (ie: for cbsaFD in cbsaFD_set). In a prior step, the 'bgCentroids', 'proForma' and 'AOIs' were clipped to the extent of the the CBSA boundary with which they intersect using SelectLayerByLocation.
arcpy.env.workspace = r"C:\ArcGIS\SYSTEM\COF\Data\CapitalOne.gdb\CBSA_12345"
arcpy.env.overwriteOutput = True
GDB = r"C:\ArcGIS\SYSTEM\COF\Data\CapitalOne.gdb"
cbsaFD = "CBSA_12345"
bgCentroids = r"C:\ArcGIS\SYSTEM\COF\Data\CapitalOne.gdb\CBSA_12345\CBSA_12345_bgCentroids"
proForma = r"C:\ArcGIS\SYSTEM\COF\Data\CapitalOne.gdb\CBSA_12345\CBSA_12345_proForma"
AOIs = r"C:\ArcGIS\SYSTEM\COF\Data\CapitalOne.gdb\CBSA_12345\CBSA_12345_RN"
inOrigins = bgCentroids
inDestinations = proForma
inNetworkDataset = r"C:\ArcGIS\Business Analyst\US\Data\StreetMapData\streets"
outNALayerName = "BG2Branches"
impedenceAttribute = "Length"
outLayerFile = outNALayerName + ".lyr"
outNALayer = arcpy.MakeODCostMatrixLayer_na(inNetworkDataset, outNALayerName, "Length", "", "", "", "", "", "USE_HIERARCHY", "", "NO_LINES")
outNALayer = outNALayer.getOutput(0)
subLayerNames = arcpy.na.GetNAClassNames(outNALayer)
originsLayerName = subLayerNames["Origins"]
originsFieldMap = arcpy.na.NAClassFieldMappings(outNALayer, originsLayerName)
originsFieldMap["Name"].mappedFieldName = "BG_ID"
arcpy.na.AddLocations(outNALayer, originsLayerName, inOrigins, originsFieldMap)
destinationsLayerName = subLayerNames["Destinations"]
destinationsFieldMap = arcpy.na.NAClassFieldMappings(outNALayer, destinationsLayerName)
destinationsFieldMap["Name"].mappedFieldName = "DID"
arcpy.na.AddLocations(outNALayer, destinationsLayerName, inDestinations, destinationsFieldMap)
arcpy.na.Solve(outNALayer)
So in an ArcMap Session, I can grab the result object exactly as you said by referencing the Feature Layer directly out of the TOC and export it to a table:
arcpy.TableToTable_conversion(r"BG2Branches\Lines", cbsaFD + "_ODCM")
The problem arises when I do this through Catalog. Since there is no way to reference the feature directly because ArcMap did not automatically convert the result object to a Feature Layer, I have to do this myself. No sweat, right?
arcpy.MakeFeatureLayer_management(outLayerName, cbsaFD + "ODCM", "", GDB)
Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 5748, in MakeFeatureLayer raise e ExecuteError: ERROR 000732: Input Features: Dataset BG2Branches.lyr does not exist or is not supported
So...I tried doing an arcpy.Describe and get an Object Does Not Exist error.So then I tried instantiating the result object under a variable:
Branch2BG_ODCM_LYR = arcpy.Solve(outNALayer)
Branch2BG_ODCM_LYR = Branch2BG_ODCM_LYR.getOutput(0)
print Branch2BG_ODCM_LYR
GPL0
Whoo hoo, have the object reference under a variable, yay!
arcpy.Describe(Branch2BG_ODCM_LYR)
Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\__init__.py", line 1200, in Describe
return gp.describe(value)
File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 374, in describe
self._gp.Describe(*gp_fixargs(args, True)))
IOError: "GPL0" does not exist
What in holy heck is going on here?!