Select to view content in your preferred language

Problems accessing layer information with decribe()

861
7
04-03-2012 03:24 PM
MLLO
by
Deactivated User
I am writing a standalone python script (i.e not within arcmap) that attempts to extract the coordinates of selected features (as they appear selected in the current map document).  The commands that make up my script (see below) work fine if I execute them within the python window in arcmap but not when I try to use them within a standalone script.


mxd= mapping.MapDocument(r'c:\GIS\project\map.mxd)
myLyr= mapping.ListLayers(mxd, 'features')[0]
desc= Describe(myLyr)

NB. 'features' is the name of a point feature layer. The datasource of this layer is within a personal geodatabase i.e. within test.gdb.

The script blows us when it gets to the last command in spite of the fact that myLyr is indeed a layer (I checked this when debugging). I cannot think of what I am doing wrong so any help will be appreciated.

thanks

marc
0 Kudos
7 Replies
curtvprice
MVP Esteemed Contributor
try:

desc= arcpy.Describe(myLyr)
0 Kudos
MLLO
by
Deactivated User
Hi,
I used the statement: from arcpy import *
So in theory I would not need to specify arcpy.Describe() ...

M.
0 Kudos
MathewCoyle
Honored Contributor
I am writing a standalone python script (i.e not within arcmap) that attempts to extract the coordinates of selected features (as they appear selected in the current map document).  The commands that make up my script (see below) work fine if I execute them within the python window in arcmap but not when I try to use them within a standalone script.


mxd= mapping.MapDocument(r'c:\GIS\project\map.mxd)
myLyr= mapping.ListLayers(mxd, 'features')[0]
desc= Describe(myLyr)

NB. 'features' is the name of a point feature layer. The datasource of this layer is within a personal geodatabase i.e. within test.gdb.

The script blows us when it gets to the last command in spite of the fact that myLyr is indeed a layer (I checked this when debugging). I cannot think of what I am doing wrong so any help will be appreciated.

thanks

marc


You have no closing single quote in your mxd line, so this should be a syntax error and not run at all.
0 Kudos
MLLO
by
Deactivated User
You have no closing single quote in your mxd line, so this should be a syntax error and not run at all.


Sorry, my mistake... this was a typo when copying. The code is as follows...

from arcpy import *
mxd= mapping.MapDocument(r'c:\GIS\project\map.mxd')
myLyr= mapping.ListLayers(mxd, 'features')[0]
desc= Describe(myLyr)

NB. 'features' is the name of a point feature layer. The datasource of this layer is within a personal geodatabase i.e. within test.gdb.
0 Kudos
MathewCoyle
Honored Contributor
Just to clarify. A personal geodatabase is an .mdb file, a file geodatabase is a .gdb.

You can try getting the feature class describe instead of layer using this, see if that works.
desc = Describe(myLyr.dataSource)


Edit:
If you do want to get the layer describe you can do this.
MakeFeatureLayer_management(myLyr, "describe_me")
desc = Describe("describe_me")
0 Kudos
MLLO
by
Deactivated User
Thank you mzcoyle,

Your first suggestion (1) but not (2)

(1)
desc = Describe(myLyr.dataSource)


(2)

MakeFeatureLayer_management(myLyr, "describe_me")
desc = Describe("describe_me")
0 Kudos
David_JAnderson
Regular Contributor
I think the layer describe function is one that works in the ArcMap command line window but not in stand alone python
I ran this code

mxd=arcpy.mapping.MapDocument('CURRENT')
df=arcpy.mapping.ListDataFrames(mxd,'Wyoming')[0]
test_layer=arcpy.mapping.ListLayers(mxd,'*',df)[1]
desc=arcpy.Describe(test_layer)
desc.FIDSet


I get a result set back from this commands.


Running the same commands in an IDLE window, with the exception of using the full path instead of CURRENT I get this message:
Traceback (most recent call last):
File "<pyshell#103>", line 1, in <module>
desc=arcpy.Describe(test_layer)
File "C:\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 862, in Describe
return gp.describe(*args)
File "C:\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 372, in describe
self._gp.Describe(*gp_fixargs(args)))
IOError: S_USA.State selection


I seem to recall another discussion where things don't work the same between stand alone and ArcMap arcpy.

Found the thread:
http://forums.arcgis.com/threads/15433-Python-Errors-in-IDLE-but-Works-in-ArcCatalog

ESRI really needs to fix this behavior. It is very frustrating to try to develop code that should behave identically but instead is dependent on which version of arcpy is being used.
0 Kudos