Select to view content in your preferred language

Layer and calculate

807
3
08-09-2012 07:55 AM
TonyAlmeida
MVP Regular Contributor
I would basically like to add an "Acres" field to the "selected" layer on the TOC regardless to the layers location on the TOC.
I am aware on how to do this with VBA but not with Python. I can't seem to find an arcy equivalent to  pMxDoc.Selectedlayers to start off with.

Any help would be great!
Thanks.
Tags (2)
0 Kudos
3 Replies
by Anonymous User
Not applicable
This should work:

arcpy.env.workspace = r"<some/data/location>"

fc =  'Parcels.shp'
flyr = 'Parcels'
field = 'Acres'
expression = '!shape.area@acres!'

try:
    arcpy.MakeFeatureLayer_management(fc, flyr)
    arcpy.AddField_management(flyr, 'Acres', 'DOUBLE')
    arcpy.CalculateField_management(flyr, field, expression, 'PYTHON')


Caleb
0 Kudos
TonyAlmeida
MVP Regular Contributor
This would only work if there was parcels.shp layer correct?
Is there a way to do this to any layer that is selected on the TOC?

Thank you for the reply i really appreciate it!
0 Kudos
by Anonymous User
Not applicable
Tony,

I am sorry, I completely misunderstood what you meant.  I'm sure that is possible, however I do not know how to do that.  I'm sure someone will see this thread and can post how to do this.  In the meantime you could look at the arcpy.mapping modules information.  You could probably find the arcpy solution in there.

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Introduction_to_arcpy_mapping/00s30000...

Caleb
0 Kudos