arcpy Service Layer doesn't support Service Properties

1950
7
06-20-2013 12:39 AM
SchoppMatthieu
New Contributor III
Hello,

I've got a mxd that only contains ArcGIS MapServices :

So I'm like :

for myLyr in arcpy.mapping.ListLayers(mxd):
    print ("Is this service layer ? : " + str(myLyr.isServiceLayer))
    print ("Does it support service properties ? : " + str(myLyr.supports("SERVICEPROPERTIES")))


Then I get :

Is this service layer ? : True
Does it support service properties ? : False
Is this service layer ? : True
Does it support service properties ? : False
Is this service layer ? : True
Does it support service properties ? : False


In ArcGIS help center, from the Layer class,  I read :

serviceProperties : "Provides access to connection information for ArcSDE and web service layers. etc"
isServiceLayer : "Returns True if a layer is a GIS service layer. GIS services are automated geographic information services that are published and accessed over the web using standard technologies and protocols."

Can someone highlight me about this flagrant contradiction ?

Thank you,
Matt
Tags (2)
0 Kudos
7 Replies
SchoppMatthieu
New Contributor III
I didn't explain the whole context :

I'm trying to get the service layer properties from a map document created from the "ConvertWebMapToMapDocument" function.

If I manually had a service layer into a map document and then run the script above, then it works. The top node of the serviceLayer supports "serviceProperties"

However if I run the same script against a mxd that have been generated from the "ConvertWebMapToMapDocument" then the top node of the serviceLayer doesn't seem to be recognized as the ServiceLayer root and doesn't supports "serviceProperties".
0 Kudos
JeffMoulds
Esri Contributor
We have a bug with Layer.supports("SERVICEPROPERTIES") not working for all types of service layers, and this is what you are hitting.

When searching for service layers in a map document returned from ConvertWebMapToMapDocument, use Layer.isServiceLayer, like in this tutorial. For example:
import arcpy
import os
import uuid

# Input WebMap json
Web_Map_as_JSON = arcpy.GetParameterAsText(0)

# The template location in the server data store
templateMxd = '//MyComputer/MyDataStore/BasicTutorial/LG_062912_10.1/LG_062912_10.1/LGIM_World_Topo_Map_v1.5.mxd'
   
# Convert the WebMap to a map document
result = arcpy.mapping.ConvertWebMapToMapDocument(Web_Map_as_JSON, templateMxd)
mxd = result.mapDocument

# Reference the data frame that contains the webmap
# Note: ConvertWebMapToMapDocument renames the active dataframe in the template_mxd to "Webmap"
df = arcpy.mapping.ListDataFrames(mxd, 'Webmap')[0]

# Remove the service layer
# This will just leave the vector layers from the template
for lyr in arcpy.mapping.ListLayers(mxd, data_frame=df):
    if lyr.isServiceLayer:
        arcpy.mapping.RemoveLayer(df, lyr)
        
# Use the uuid module to generate a GUID as part of the output name
# This will ensure a unique output name
output = 'WebMap_{}.pdf'.format(str(uuid.uuid1()))
Output_File = os.path.join(arcpy.env.scratchFolder, output)

# Export the WebMap
arcpy.mapping.ExportToPDF(mxd, Output_File) 

# Set the output parameter to be the output file of the server job
arcpy.SetParameterAsText(1, Output_File)

# Clean up - delete the map document reference
filePath = mxd.filePath
del mxd, result
os.remove(filePath)
0 Kudos
JeffMoulds
Esri Contributor
BTW, for your records, the tracking number for the aforementioned bug is NIM092553.
0 Kudos
SchoppMatthieu
New Contributor III
Ok, thank you for your answer 🙂
0 Kudos
MarkusSchenardi
Occasional Contributor
I can not find these NIM in the issues list for 10.2.1. (http://downloads.esri.com/support/downloads/other_/1021-IssuesAddressedList.pdf)

Is there another way to query mapservice Information using arcpy? I need to find out the URL of a arcgis server layer inside a mxd.
Markus Schenardi
Laixo AG - Zürich - Switzerland
Member of the Esri Partner Network
0 Kudos
deleted-user-Jie3eyjOl9XM
Occasional Contributor

I'm looking for a workaround for this, too. Given the MXD that was created from the webmap json, how can I get the URL for a service layer? It seems so simple, but I'm so stuck.

0 Kudos
MarkusSchenardi
Occasional Contributor

We used the following workaround:

1) in the webapplication, extend the printtask and set layername or id = service-URL.

2) in the pythonscript: take the serviceurl from the name attribute

Markus Schenardi
Laixo AG - Zürich - Switzerland
Member of the Esri Partner Network
0 Kudos