Publishing script tool as Geoprocessing Service - Input turned as Constant Value

865
6
Jump to solution
12-28-2023 03:51 AM
User35489
Occasional Contributor III

 

Hello,

A tool created for conversion, worked fine on ArcGIS Pro, but while/when published the Input value changed to constant value, need kindly help

Environment: ArcGIS Pro 3.2.1, ArcGIS Enterprise 11.1

def getParameterInfo(self):
"""Define the tool parameters."""
params = [
arcpy.Parameter(displayName="Input CAD File",
name="in_cad",
datatype="DECadDrawingDataset",
parameterType="Required",
direction="Input"),
arcpy.Parameter(displayName="Output JSON File",
name="out_json",
datatype="DEFile",
parameterType="Required",
direction="Output")
]
return params

def execute(self, parameters, messages):
"""The source code of the tool."""
in_cad = parameters[0].valueAsText
out_json = parameters[1].valueAsText

desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')

newpath = desktop+str(r'\output')
if not os.path.exists(newpath):
os.makedirs(newpath)

arcpy.env.workspace = desktop+r"\output\fGDB.gdb"

# Set local variables

out_folder_path = desktop+str(r"\output" )
out_name = "fGDB.gdb"

# Execute Create FileGDB, temp

arcpy.CreateFileGDB_management(out_folder_path, out_name)

#####################################

# Process: CAD to Geodatabase
arcpy.CADToGeodatabase_conversion(in_cad, out_folder_path+'/'+out_name, "FClass", "1000", "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];-400 -400 11258999068426.2;-1073.7418235 4194304001953.12;-100000 10000;8.98315284119522E-09;0.001;0.001;IsHighPrecision")

#####################################

# Process: Iterate Feature Classes

datasets = arcpy.ListDatasets(feature_type='feature')
datasets = [''] + datasets if datasets is not None else []

for ds in datasets:
for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
path = os.path.join(arcpy.env.workspace, ds, fc)
print(path)

#####################################

# Process: Features To JSON
arcpy.FeaturesToJSON_conversion(fc, out_json, "FORMATTED", "NO_Z_VALUES", "NO_M_VALUES", "GEOJSON")

#####################################

# Execute Delete FileGDB

arcpy.Delete_management(newpath)
return

 

0 Kudos
1 Solution

Accepted Solutions
User35489
Occasional Contributor III

Further in research,

CAD file data type is considered as a non-simple feature. Thus it cannot be used as a user input.

https://enterprise.arcgis.com/en/server/10.5/publish-services/windows/parameter-data-type-transforma...

View solution in original post

0 Kudos
6 Replies
Brian_Wilson
Occasional Contributor III

First thing that pops out at me is the indentation is wrong. Did that change when you uploaded it to this web site or is it really like that. I don't know if I got the for loops indented correctly around line 52....

 

import os
import arcpy

def getParameterInfo(self):
    """Define the tool parameters."""
    params = [
        arcpy.Parameter(displayName="Input CAD File",
        name="in_cad",
        datatype="DECadDrawingDataset",
        parameterType="Required",
        direction="Input"),
        arcpy.Parameter(displayName="Output JSON File",
        name="out_json",
        datatype="DEFile",
        parameterType="Required",
        direction="Output")
    ]
    return params

def execute(self, parameters, messages):
    """The source code of the tool."""
    in_cad = parameters[0].valueAsText
    out_json = parameters[1].valueAsText

    desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')

    newpath = desktop+str(r'\output')
    if not os.path.exists(newpath):
        os.makedirs(newpath)

    arcpy.env.workspace = desktop+r"\output\fGDB.gdb"

    # Set local variables

    out_folder_path = desktop+str(r"\output" )
    out_name = "fGDB.gdb"

    # Execute Create FileGDB, temp

    arcpy.CreateFileGDB_management(out_folder_path, out_name)

    #####################################
    # Process: CAD to Geodatabase
    arcpy.CADToGeodatabase_conversion(in_cad, out_folder_path+'/'+out_name, "FClass", "1000", "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];-400 -400 11258999068426.2;-1073.7418235 4194304001953.12;-100000 10000;8.98315284119522E-09;0.001;0.001;IsHighPrecision")

    #####################################
    # Process: Iterate Feature Classes

    datasets = arcpy.ListDatasets(feature_type='feature')
    datasets = [''] + datasets if datasets is not None else []

    for ds in datasets:
        for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
            path = os.path.join(arcpy.env.workspace, ds, fc)
            print(path)

    #####################################
    # Process: Features To JSON
    arcpy.FeaturesToJSON_conversion(fc, out_json, "FORMATTED", "NO_Z_VALUES", "NO_M_VALUES", "GEOJSON")

    #####################################
    # Execute Delete FileGDB

    arcpy.Delete_management(newpath)
    return

 

0 Kudos
User35489
Occasional Contributor III

@Brian_Wilson Indentation is correct in the code, somehow it got posted wrong, all without indents. The tool worked fine in ArcGIS Pro.

0 Kudos
User35489
Occasional Contributor III

Even while publishing, it has got the same issue.

User35489_0-1703835908888.png

 

0 Kudos
Brian_Wilson
Occasional Contributor III

It looks like you did not include the complete code, aside from the indentation problem. If you are setting up a "Script" then you specify parameters in the Toolbox. If you are setting up a Python Toolbox then there is code that wraps around what you posted. The imports at the top then the class definition for the Python Toolbox and the class for the tool.

If you post the whole thing (with correct indentation) then I can paste it into my editor and try it out. Then maybe I can help with the actual error.

When you open the "code" window here, make sure you select "Python" before you paste your code into it. That's probably why it removed all the indentation. It defaults to "C". (Bad choice)

 

0 Kudos
User35489
Occasional Contributor III

@Brian_Wilson Please find below. Thanks for your interest.

# -*- coding: utf-8 -*-

import arcpy


class Toolbox:
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "toolbox"
        self.alias = "toolbox"

        # List of tool classes associated with this toolbox
        self.tools = [Tool]


class Tool:
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "DWGtoGEOJSON"
        self.description = ""

    def getParameterInfo(self):
        """Define the tool parameters."""
        params = [
            arcpy.Parameter(displayName="Input CAD File",
                            name="in_cad",
                            datatype="DECadDrawingDataset",
                            parameterType="Required",
                            direction="Input"),
            arcpy.Parameter(displayName="Output JSON File",
                            name="out_json",
                            datatype="DEFile",
                            parameterType="Required",
                            direction="Output")
        ]
        return params

    def isLicensed(self):
        """Set whether the tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter. This method is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
        in_cad = parameters[0].valueAsText
        out_json = parameters[1].valueAsText
        
        desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop') 

        newpath = desktop+str(r'\output') 
        if not os.path.exists(newpath):
            os.makedirs(newpath)

        arcpy.env.workspace = desktop+r"\output\fGDB.gdb"

        # Set local variables

        out_folder_path = desktop+str(r"\output" )
        out_name = "fGDB.gdb"

        # Execute Create FileGDB, temp

        arcpy.CreateFileGDB_management(out_folder_path, out_name)

        #####################################

        # Process: CAD to Geodatabase
        arcpy.CADToGeodatabase_conversion(in_cad, out_folder_path+'/'+out_name, "FClass", "1000", "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];-400 -400 11258999068426.2;-1073.7418235 4194304001953.12;-100000 10000;8.98315284119522E-09;0.001;0.001;IsHighPrecision")

        #####################################

        # Process: Iterate Feature Classes

        datasets = arcpy.ListDatasets(feature_type='feature')
        datasets = [''] + datasets if datasets is not None else []

        for ds in datasets:
            for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
                path = os.path.join(arcpy.env.workspace, ds, fc)
                print(path)

        #####################################

        # Process: Features To JSON
        arcpy.FeaturesToJSON_conversion(fc, out_json, "FORMATTED", "NO_Z_VALUES", "NO_M_VALUES", "GEOJSON")

        #####################################

        # Execute Delete FileGDB

        arcpy.Delete_management(newpath)        
        return

    def postExecute(self, parameters):
        """This method takes place after outputs are processed and
        added to the display."""
        return

 

0 Kudos
User35489
Occasional Contributor III

Further in research,

CAD file data type is considered as a non-simple feature. Thus it cannot be used as a user input.

https://enterprise.arcgis.com/en/server/10.5/publish-services/windows/parameter-data-type-transforma...

0 Kudos