In the ArcGIS Desktop arcpy method CreateMapSDDraft it output a dictionary of the analysis results. This was easy to parse and perform actions before publication takes place. https://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/createmapsddraft.htm
In ArcGIS Pro it is a bit unclear the results of the analysis.
The Stage Service does not explicitly state this except in one of the examples uses the arcpy.GetMessages(1) call to get the warnings. This appears to be text and not the easiest to parse.
https://pro.arcgis.com/en/pro-app/latest/tool-reference/server/stage-service.htm
My parsing attempt: analysisMessages = eval(arcpy.GetMessages(1).split('(')[1][:-2].strip())
Is there another way to get the analysis results as a dictionary? It appears we have lost some functionality as we would like to look for any "copy to server" warnings before the publication process.
Can you just set the output of the sddraft to a variable and access it that way? I only have a CreateGeocodeSDDraft() to check this on, but doing this:
analyze_messages = arcpy.CreateGeocodeSDDraft(params and stuff)
give mes this in the debugger:
analyze_messages = {'errors': {}, 'warnings': {('Locator will be copied to the server', 24044): []}, 'messages': {('Composite locator will be copied to the server', 30009): []}}
Jeff thanks for the suggestion. This is interesting the workflow attempted here is with Map Services and very interesting they are different. What you are sharing makes sense from the workflow perspective and appears to work for Geocode SD drafts but not for map service drafts.
I am using:
It seems silly and in some way too late these messages are only returned when the arcpy.StageService occurs because when layers are identified as not registered with server, the process creating the .sd can take forever. In the old Map Service workflow this would not have progresses this far since our older scripts would warn the publisher to resolve the data sources before publication. In past. the layer data source is not registered warnings occurred during the create draft phase and now this is part of staging?
Yeah, it was worth a shot. I have some maps that I want to automate like this so I'll keep it in mind while creating the scripts and will take a look at it from the CreateSharingDraft onward. I'm finding this process of automating publishing to be a lot more extensive and a lot less documented. Especially for publishing routing services and the 'Create Route Analysis Layer' creating serialized datasets in the workspace instead of overwriting the one. Not very efficient.
@RonnieRichards Did you figure anything out on this? I'm having about the same issue... setting sharing_draft.copyDataToServer = False and I want to be able to get the 'data source not registered' warning/error BEFORE creating the .sd file. So far it will copy all the data locally, then tell me it's not registered. Which is especially not good for large datasets. The 'analyze' button in the UI must be doing something that's not exposed to the api or gp toolset?
Hello @FredSpataro no never figured this out. Ended up checking the analysis messages during the stage process similar to the examples they have published in the MapServiceDraft help.
However this is not very desirable as you describe it takes for ever for large maps with unregistered data sources to copy to local data... and then for us to fail the script because this may not be the desirable result. Not sure why the difference in this workflow compared to Geocode Drafts or legacy MXD publications but certainly is not optimal and different than the UI experience.
Thanks for the follow up... looks like someone else created an 'idea' for this: https://community.esri.com/t5/arcgis-pro-ideas/add-an-arcpy-mapping-analyzeforsd-equivalent-to/idc-p...
but classically not getting thru ...
It looks like the old AnalyzeForSD is still there library but is appears to fail opening the APRX ...
from an ArcMap 10.8 install: mapping.py:
def AnalyzeForSD(sddraft):
"""AnalyzeForSD(sddraft)
Analyzes Service Definition Draft ( .sddraft ) files to determine
suitability and sources of potential performance issues before converting
a Service Definition Draft file to a Service Definition ( .sd ) file.
sddraft(String):
A string that represents the path and file name for the Service Definition
Draft ( .sddraft ) file."""
import arcgisscripting
return convertArcObjectToPythonObject(arcgisscripting._analyzeForSD(*gp_fixargs([sddraft], True)))
My attempt at running this in Pro... all the imports work and it seems to start reading the sddraft
from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject
import arcgisscripting
from arcpy.geoprocessing._base import gp_fixargs
sddraft = r"C:\Temp\Map.sddraft"
r = convertArcObjectToPythonObject(arcgisscripting._analyzeForSD(*gp_fixargs([sddraft], True)))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: C:\Temp\Map.aprx