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

PyScript, simple error help! Field Mapping Object

$
0
0
Okay. This first block of code will run with no error and work just fine.
Code:

import arcpy
...
... arcpy.env.workspace = "G:\ChrisGIS\WDFW_NWIFC_EVENT_17100101.gdb"
... arcpy.env.overwriteOutput = "True"
... #Variables
... workspace = "G:\ChrisGIS\WDFW_NWIFC_EVENT_17100101.gdb"
... inputFC = "WDFW_CHFA_2HEM_evt_1"
... targetFC = "WDFW_CHFA_2HEM_evt_olay_1"
...
...
... fm_permid = arcpy.FieldMap()
... fm_reach = arcpy.FieldMap()
... fms = arcpy.FieldMappings()
...
...
...
... fm_permid.addInputField(inputFC,"Permanent_Identifier")
... permid_name = fm_permid.outputField
... permid_name.name = "Permanent_ID"
... fm_permid.outputField = permid_name
...
... fm_reach.addInputField(inputFC,"ReachCode")
... reach_name = fm_reach.outputField
... reach_name.name = "ReachCode"
... fm_reach.outputField = reach_name
...
... fms.addFieldMap(fm_permid)
... fms.addFieldMap(fm_reach)
...
... # Process: Append
... arcpy.Append_management(workspace+"\\"+inputFC, workspace+"\\"+targetFC,"NO_TEST",fms)

I change the above code slightly, by adding another FieldMap which is strnm. But it generates an error. I made what I added in red so you can easily locate it. Here is that code
Code:

import arcpy

arcpy.env.workspace = "G:\ChrisGIS\WDFW_NWIFC_EVENT_17100101.gdb"
arcpy.env.overwriteOutput = "True"
#Variables
workspace = "G:\ChrisGIS\WDFW_NWIFC_EVENT_17100101.gdb"
inputFC = "WDFW_CHFA_2HEM_evt_1"
targetFC = "WDFW_CHFA_2HEM_evt_olay_1"

fm_strnm = arcpy.FieldMap ()
fm_permid = arcpy.FieldMap()
fm_reach = arcpy.FieldMap()
fms = arcpy.FieldMappings()



fm_permid.addInputField(inputFC,"Permanent_Identifier")
permid_name = fm_permid.outputField
permid_name.name = "Permanent_ID"
fm_permid.outputField = permid_name

fm_reach.addInputField(inputFC,"ReachCode")
reach_name = fm_reach.outputField
reach_name.name = "ReachCode"
fm_reach.outputField = reach_name

fm_strnm.addInputField(inputFC,"STRM_NAME")
strnm_name = fm_strnm.outputField
strnm_name.name = "LLID_STRM_NAME"
strnm.outputField = strnm_name


fms.addFieldMap(fm_permid)
fms.addFieldMap(fm_reach)
fms.addFieldMap(fm_strnm)
# Process: Append
arcpy.Append_management(workspace+"\\"+inputFC, workspace+"\\"+targetFC,"NO_TEST",fms)
Runtime error <type 'exceptions.NameError'>: name 'strnm' is not defined

I do not understand this. I do not change anything, and pretty much copy the first block of code and simply try to add one more object. Any help would be great!! I am still very green to scripting and this is my first time messing with the FieldMappings Object.

Viewing all articles
Browse latest Browse all 2485

Latest Images

Trending Articles



Latest Images