Dealing with Group Layers in scripts

698
6
06-28-2011 05:32 AM
yonatanrubinstein
New Contributor III
Hello,

I'm working on ArcGIS 9.3.1 and I run a python script which basically does a "select by location" query to several SDE layers which appear on the ArcMAP TOC (using a polygon shapefile the user points to) and copies the selected features to a new shapefile.

THE PROBLEM IS that some layers are within a group layer, and then the script gives a error stating :

<class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid.
ERROR 000840: The value is not a Feature Layer.
Failed to execute (SelectLayerByLocation)

now I understand that group layer is not a feature Layer and that SelectLayerByLocation only accepts feature Layers, that's where my question fits in:

Question: How can I reach a feature layer inside a Group layer using python code? or better yet, how can I tell what kind of layer I'm dealing with (Feature\group layer) using python code(describe method doesn't work on group)?

Thanks in Advance.
0 Kudos
6 Replies
DaleHoneycutt
Occasional Contributor III
If your group layer name is "Infrastructure" and a layer w/in that group layer is "Streets", then you can find the group in Python with "Infrastructure\Streets"
0 Kudos
yonatanrubinstein
New Contributor III
If your group layer name is "Infrastructure" and a layer w/in that group layer is "Streets", then you can find the group in Python with "Infrastructure\Streets"


Thanks for the quick response. However, it did not work - I tried this solution and got the following error message:

<class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid.
ERROR 000732: Input Feature Layer: Dataset background\houses does not exist or is not supported
Failed to execute (SelectLayerByLocation).
0 Kudos
DaleHoneycutt
Occasional Contributor III
Sorry: use a forward slash instead of a backward slash, as in "Infrastructure/Streets"
0 Kudos
yonatanrubinstein
New Contributor III
Sorry: use a forward slash instead of a backward slash, as in "Infrastructure/Streets"


Thanks, but unfortunately, this doesn't work either - the same error message as above is given by the system.
0 Kudos
DaleHoneycutt
Occasional Contributor III
Are you running the script as a stand-alone script or as a script tool?  In order to use layers, you need a script tool that's running 'inside' arcmap.  See An overview of creating script tools for an explanation of script tools vs. stand-alone scripts.

Other than the above, I don't know why it's not working.
0 Kudos
yonatanrubinstein
New Contributor III
Hi, Dale - Thanks a million for trying to help me out.

I'm using a script tool - I run my script through ArcToolbox and a tool I built, so I guess your answer doesn't answer to my problem - but thanks, you've given me a idea to check maybe there is a tool background property that changing it will help me (i doubt it, but it's worth checking).

I'll return to say if this step will help in anyway but thanks in advance.
0 Kudos