AnsweredAssumed Answered

use layer name instead of alias for tool input

Question asked by rbasaria_DTS on Mar 30, 2018
Latest reply on Apr 13, 2018 by rbasaria_DTS

Hello. I have created an ArcGIS tool that runs through a join, selection by attributes, and various field calculations. The tool works, assuming the input for the tool is the actual feature class name, however, many of the feature classes that this tool will be used for have aliases. As such, when the layers are selected from ArcMap, the alias is passed as the parameter rather than the actual FC name, which breaks the tool. 

 

I think my biggest problem here is that I don't know what I am looking for to address this. Essentially, I want the tool to ignore the alias and use the actual FC name. Is there a way to do this? I thought maybe something with the GetParameter portion of the tool that defines the first 2 variables would work, but I don't really know where to start looking. Any ideas?

 

Here is my code:

 

import arcpy, sys, string, os, subprocess

gdfc = arcpy.GetParameterAsText(0)
vwfc = arcpy.GetParameterAsText(1)

gca = vca = "Conservation_Area_Name"
gcn = vcn = "Conservation_Area_Number"
gn = vn = "Network"

gfi = "Field_ID"
gai = "Asset_ID"
gt1n = "Tier_1_System_Name"
gt1t = "Tier_1_System_Type"
gt2n = "Tier_2_Major_Subsystem_Name"
gt2t = "Tier_2_Major_Subsystem_Type"
gt3n = "Tier_3_Minor_Subsystem_Name"
gt3t = "Tier_3_Minor_Subsystem_Type"
gt4n = "Asset_Name"

vfi = "FieldID"
vai = "AssetID"
vt1n = "Tier_1_Name"
vt1t = "Tier_1_Type"
vt2n = "Tier_2_Name"
vt2t = "Tier_2_Type"
vt3n = "Tier_3_Name"
vt3t = "Tier_3_Type"
vt4n = "Tier_4_Name"

slct = gdfc+"."+gai+" IS NULL OR ("+gdfc+"."+gai+" <> "+vwfc+"."+vai+")"

try:
    arcpy.AddJoin_management(gdfc, gfi, vwfc, vfi)
    arcpy.SelectLayerByAttribute_management(gdfc, "NEW_SELECTION", slct)
    arcpy.CalculateField_management(gdfc, gdfc+"."+gai, "["+vwfc+"."+vai+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gca, "["+vwfc+"."+vca+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gcn, "["+vwfc+"."+vcn+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gn, "["+vwfc+"."+vn+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gt1n, "["+vwfc+"."+vt1n+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gt1t, "["+vwfc+"."+vt1t+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gt2n, "["+vwfc+"."+vt2n+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gt2t, "["+vwfc+"."+vt2t+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gt3n, "["+vwfc+"."+vt3n+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gt3t, "["+vwfc+"."+vt3t+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gt4n, "["+vwfc+"."+vt4n+"]", "VB", "")
except:
    print arcpy.GetMessages()
   
arcpy.RemoveJoin_management(gdfc)
arcpy.SelectLayerByAttribute_management(gdfc, "CLEAR_SELECTION", "")

Outcomes