Select to view content in your preferred language

How to publish a mxd file via arcpy

1834
5
01-13-2017 02:23 AM
aleho123
Deactivated User

Hello,

I want to publish a mxd file via arcpy. I checked the examples in the documentation - unfortunately it is not working. the code is:

sd_draft = arcpy.mapping.CreateMapSDDraft(map_document, sd_draft_file, service_name, "FROM_CONNECTION_FILE", connection_file, True, None, summary, tags)

if sd_draft["errors"] == {}:
    arcpy.StageService_server(sd_draft_file, sd_file)
    arcpy.UploadServiceDefinition_server(sd_file, connection_file)

at CreateMapSDDraft the following error occurs:
File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\mapping.py", line 398, in CreateMapSDDraft
    return convertArcObjectToPythonObject(arcgisscripting._createMapSDDraft(*gp_fixargs([map_document, out_sddraft, service_name, server_type, connection_file_path, copy_data_to_server, folder_name, summary, tags], True, False)))

Error Info:
The system cannot locate the object specified.

I checked - the paths to the connection file and the mxd file are correct. We are also running on the latest Version. But I cant find any sd files on the server for existing services. Any idea, why I cant find those files?

Any help, very welcome.

Tags (2)
0 Kudos
5 Replies
FC_Basson
MVP Regular Contributor

How did you define the "map_document" parameter?

0 Kudos
aleho123
Deactivated User
map_document = arcpy.mapping.MapDocument("PATH\\TO_MXD_FILE")
0 Kudos
DanPatterson_Retired
MVP Emeritus

CreateMapSDDraft—Help | ArcGIS Desktop 

shows

A draft service definition does not contain data. A draft service alone cannot be used to publish a service.

then

The Service Definition Draft can then be converted to a fully consolidated Service Definition (.sd) file using the Stage Service tool. Staging compiles all the necessary information needed to successfully publish the GIS resource. If your data is not registered with the server, the data will be added when the Service Definition Draft is staged. Finally, the Service Definition file can be uploaded and published as a GIS service to a specified GIS server using the Upload Service Definition tool. This step takes the Service Definition file, copies it onto the server, extracts required information, and publishes the GIS resource. For more information, see the overview of the Publishing toolset.

which suggests you aren't done the process

0 Kudos
aleho123
Deactivated User

yes - of course. because the script failed before and didn't execute the following steps.

Which are as far as I know: arcpy.StageService_server and arcpy.UploadServiceDefinition_server

To call StageService_server I would need an existing sddraft - so, as long as the function CreateMapSDDraft fails, I am stuck there.

0 Kudos
KevinHibma
Esri Regular Contributor

Anna, I think you'll need to add a little more of your code to the question.

My best guess is it cant find one of: 1) input MXD 2) output location for the .SDDRAFT file or 3) the .AGS connection file

0 Kudos