Summary: I can create a ServiceDefinition through ArcCatalog or ArcMap, but when I try to generate the ServiceDefinition through python, it does not copy the /data folder with it, thus the script fails when published to the server.
Details:
I'm using ArcGIS 10.2.2.3552
My toolbox script has one string input parameter and one string output parameter
I have a custom python toolbox that I need to put on an ArcGIS server. The requirements from the system administrator is that I give him a .sd (ServiceDefinition) file.
I can successfully create the .sd file through ArcCatalog by running my python tool and then sharing it as a service. The problem with this is that it is a very long process, and every step (run the tool, right click result share as service, analyze the tool, stage the tool) takes a very long time.
What I am trying do is create a python script that will fully automate the process of creating a ServiceDefinition file.
When I AnalyzeForSD, I keep getting an error in the analyzeMessages saying 'ERROR 001238: Script myTool contains broken project data source: data'. I can't figure out how to resolve this error.
I figured I could just ignore the error and try to create the ServiceDefinition anyway. So then the .sd file is created, but it doesn't copy /data folder.
I have tried copy_data_to_server=True and =False, but neither one actually copies the data.
Any ideas?
Here's my directory structure
import arcpy import sys import os scriptPath = sys.path[0] toolboxPath = os.path.join(scriptPath, 'Toolbox.tbx') sdDraftPath = os.path.join(scriptPath, 'Toolbox.sddraft') sdPath = os.path.join(scriptPath, 'Toolbox.sd') #import the toolbox arcpy.ImportToolbox(toolboxPath, 'customModule') #execute the tool result = arcpy.myTool_customModule('hello') try: os.remove(sdDraftPath) except: pass try: os.remove(sdPath) except: pass arcpy.CreateGPSDDraft(result, sdDraftPath, 'Toolbox', server_type="ARCGIS_SERVER", copy_data_to_server=False, folder_name=None, summary='Summary', tags='Some Tags') analyzeMessages = arcpy.mapping.AnalyzeForSD(sdDraftPath) if analyzeMessages['errors'] != {}: # if the sddraft analysis contained errors, display them print analyzeMessages['errors'] raise Exception('There were errors while generating the service definition') arcpy.StageService_server(sdDraftPath, sdPath) Here is myTool.py. Obviously this isn't my actual script, but it is an example that reproduces the problem.
import arcpy import os import sys input = arcpy.GetParameterAsText(0) #print input to the console arcpy.AddMessage('You passed in ' + input) scriptPath = sys.path[0] #make a variable pointing to my data so that ESRi's code will realize #that this data needs to be packaged with the script dataPath = os.path.join(scriptPath, 'data') arcpy.AddMessage(dataPath) mxdPath = os.path.join(dataPath, 'MapData.mxd') #read a file from the data folder dataFilePath = os.path.join(dataPath, 'TextData.txt') with open(dataFilePath, 'r') as fin: arcpy.AddMessage(fin.read()) mxd = arcpy.mapping.MapDocument(mxdPath) arcpy.AddMessage(arcpy.mapping.ListLayers(mxd)) #write something to the output parameter arcpy.SetParameterAsText(1, arcpy.mapping.ListLayers(mxd))
أكثر...
Details:
I'm using ArcGIS 10.2.2.3552
My toolbox script has one string input parameter and one string output parameter
I have a custom python toolbox that I need to put on an ArcGIS server. The requirements from the system administrator is that I give him a .sd (ServiceDefinition) file.
I can successfully create the .sd file through ArcCatalog by running my python tool and then sharing it as a service. The problem with this is that it is a very long process, and every step (run the tool, right click result share as service, analyze the tool, stage the tool) takes a very long time.
What I am trying do is create a python script that will fully automate the process of creating a ServiceDefinition file.
When I AnalyzeForSD, I keep getting an error in the analyzeMessages saying 'ERROR 001238: Script myTool contains broken project data source: data'. I can't figure out how to resolve this error.
I figured I could just ignore the error and try to create the ServiceDefinition anyway. So then the .sd file is created, but it doesn't copy /data folder.
I have tried copy_data_to_server=True and =False, but neither one actually copies the data.
Any ideas?
Here's my directory structure
- Toolbox.tbx
- generateServiceDefinition.py
- ToolData
- myTool.py
- data
- MapData.mxd
- TextData.txt
import arcpy import sys import os scriptPath = sys.path[0] toolboxPath = os.path.join(scriptPath, 'Toolbox.tbx') sdDraftPath = os.path.join(scriptPath, 'Toolbox.sddraft') sdPath = os.path.join(scriptPath, 'Toolbox.sd') #import the toolbox arcpy.ImportToolbox(toolboxPath, 'customModule') #execute the tool result = arcpy.myTool_customModule('hello') try: os.remove(sdDraftPath) except: pass try: os.remove(sdPath) except: pass arcpy.CreateGPSDDraft(result, sdDraftPath, 'Toolbox', server_type="ARCGIS_SERVER", copy_data_to_server=False, folder_name=None, summary='Summary', tags='Some Tags') analyzeMessages = arcpy.mapping.AnalyzeForSD(sdDraftPath) if analyzeMessages['errors'] != {}: # if the sddraft analysis contained errors, display them print analyzeMessages['errors'] raise Exception('There were errors while generating the service definition') arcpy.StageService_server(sdDraftPath, sdPath) Here is myTool.py. Obviously this isn't my actual script, but it is an example that reproduces the problem.
import arcpy import os import sys input = arcpy.GetParameterAsText(0) #print input to the console arcpy.AddMessage('You passed in ' + input) scriptPath = sys.path[0] #make a variable pointing to my data so that ESRi's code will realize #that this data needs to be packaged with the script dataPath = os.path.join(scriptPath, 'data') arcpy.AddMessage(dataPath) mxdPath = os.path.join(dataPath, 'MapData.mxd') #read a file from the data folder dataFilePath = os.path.join(dataPath, 'TextData.txt') with open(dataFilePath, 'r') as fin: arcpy.AddMessage(fin.read()) mxd = arcpy.mapping.MapDocument(mxdPath) arcpy.AddMessage(arcpy.mapping.ListLayers(mxd)) #write something to the output parameter arcpy.SetParameterAsText(1, arcpy.mapping.ListLayers(mxd))
أكثر...