Skip to main content
improved formatting.
Source Link
whyzar
  • 12.1k
  • 23
  • 39
  • 72

I fear I am missing something fundamental.

I can get a list of fields from one layer using ListFields, and look at the properties:

fields = arcpy.ListFields(feature_class)

# Iterate through the list of fields
for field in fields:
    # Print field properties
    print("Field:       {0}".format(field.name))
    print("Alias:       {0}".format(field.aliasName))
    print("Type:        {0}".format(field.type))
    print("Is Editable: {0}".format(field.editable))
    print("Required:    {0}".format(field.required))
    print("Scale:       {0}".format(field.scale))
    print("Precision:   {0}".format(field.precision))

Is there an easy way to add these fields with the exact same properties to a new layer using AddField_management? 

I was hoping I could pass the field object directly and not have to decompose it into the individual properties. But the following does NOT work:

for field in fields:
    # add fields with the same properties
    arcpy.AddField_managment(feature_class2,field)

It does not seem very efficient to break out and pass every field property (field.name, field.type, etc). Surely there is a better way.

I get the error:

ERROR 000623: Invalid value type for parameter field_name

I fear I am missing something fundamental.

I can get a list of fields from one layer using ListFields, and look at the properties:

fields = arcpy.ListFields(feature_class)

# Iterate through the list of fields
for field in fields:
    # Print field properties
    print("Field:       {0}".format(field.name))
    print("Alias:       {0}".format(field.aliasName))
    print("Type:        {0}".format(field.type))
    print("Is Editable: {0}".format(field.editable))
    print("Required:    {0}".format(field.required))
    print("Scale:       {0}".format(field.scale))
    print("Precision:   {0}".format(field.precision))

Is there an easy way to add these fields with the exact same properties to a new layer using AddField_management? I was hoping I could pass the field object directly and not have to decompose it into the individual properties. But the following does NOT work:

for field in fields:
    # add fields with the same properties
    arcpy.AddField_managment(feature_class2,field)

It does not seem very efficient to break out and pass every field property (field.name, field.type, etc). Surely there is a better way.

I get the error:

ERROR 000623: Invalid value type for parameter field_name

I fear I am missing something fundamental.

I can get a list of fields from one layer using ListFields, and look at the properties:

fields = arcpy.ListFields(feature_class)

# Iterate through the list of fields
for field in fields:
    # Print field properties
    print("Field:       {0}".format(field.name))
    print("Alias:       {0}".format(field.aliasName))
    print("Type:        {0}".format(field.type))
    print("Is Editable: {0}".format(field.editable))
    print("Required:    {0}".format(field.required))
    print("Scale:       {0}".format(field.scale))
    print("Precision:   {0}".format(field.precision))

Is there an easy way to add these fields with the exact same properties to a new layer using AddField_management? 

I was hoping I could pass the field object directly and not have to decompose it into the individual properties. But the following does NOT work:

for field in fields:
    # add fields with the same properties
    arcpy.AddField_managment(feature_class2,field)

It does not seem very efficient to break out and pass every field property (field.name, field.type, etc). Surely there is a better way.

I get the error:

ERROR 000623: Invalid value type for parameter field_name

edited tags; edited title
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

copy Copying exact field properties to new layer using arcpyArcPy?

I fear I am missing something fundamental.

I can get a list of fields from one layer using ListFields, and look at the properties:

fields = arcpy.ListFields(feature_class)

# Iterate through the list of fields
for field in fields:
    # Print field properties
    print("Field:       {0}".format(field.name))
    print("Alias:       {0}".format(field.aliasName))
    print("Type:        {0}".format(field.type))
    print("Is Editable: {0}".format(field.editable))
    print("Required:    {0}".format(field.required))
    print("Scale:       {0}".format(field.scale))
    print("Precision:   {0}".format(field.precision))

Is there an easy way to add these fields with the exact same properties to a new layer using AddField_management? I was hoping I could pass the field object directly and not have to decompose it into the individual properties.

The But the following does NOT work:

for field in fields:
    # add fields with the same properties
    arcpy.AddField_managment(feature_class2,field)

It does not seem very efficient to break out and pass every field property (field.name, field.type, etc). Surely there is a better way.

I get the error:

ERROR 000623: Invalid value type for parameter field_name

I fear I am missing something fundamental.

I can get a list of fields from one layer using ListFields, and look at the properties:

fields = arcpy.ListFields(feature_class)

# Iterate through the list of fields
for field in fields:
    # Print field properties
    print("Field:       {0}".format(field.name))
    print("Alias:       {0}".format(field.aliasName))
    print("Type:        {0}".format(field.type))
    print("Is Editable: {0}".format(field.editable))
    print("Required:    {0}".format(field.required))
    print("Scale:       {0}".format(field.scale))
    print("Precision:   {0}".format(field.precision))

Is there an easy way to add these fields with the exact same properties to a new layer using AddField_management? I was hoping I could pass the field object directly and not have to decompose it into the individual properties.

The following does NOT work:

for field in fields:
    # add fields with the same properties
    arcpy.AddField_managment(feature_class2,field)

I get the error:

ERROR 000623: Invalid value type for parameter field_name

I fear I am missing something fundamental.

I can get a list of fields from one layer using ListFields, and look at the properties:

fields = arcpy.ListFields(feature_class)

# Iterate through the list of fields
for field in fields:
    # Print field properties
    print("Field:       {0}".format(field.name))
    print("Alias:       {0}".format(field.aliasName))
    print("Type:        {0}".format(field.type))
    print("Is Editable: {0}".format(field.editable))
    print("Required:    {0}".format(field.required))
    print("Scale:       {0}".format(field.scale))
    print("Precision:   {0}".format(field.precision))

Is there an easy way to add these fields with the exact same properties to a new layer using AddField_management? I was hoping I could pass the field object directly and not have to decompose it into the individual properties. But the following does NOT work:

for field in fields:
    # add fields with the same properties
    arcpy.AddField_managment(feature_class2,field)

It does not seem very efficient to break out and pass every field property (field.name, field.type, etc). Surely there is a better way.

I get the error:

ERROR 000623: Invalid value type for parameter field_name

added 63 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
Loading
Source Link
Wes
  • 19
  • 1
Loading