Select to view content in your preferred language

Set Environment parameter in custom geoprocessing tool

52
1
6 hours ago
EugeneSosnin_GSI
Emerging Contributor

Hi,

I build a new geoprocessing tool, and I want to set a default outputCoordinateSystem in Environment:

EugeneSosnin_GSI_0-1748027710267.png

I found we have it tool parameters:

EugeneSosnin_GSI_1-1748027769328.png

I tried to use initializeParameters:

class ToolValidator:
  # Class to add custom behavior and properties to the tool and tool parameters.
    
    def __init__(self):
        # Set self.params for use in other validation methods.
        self.params = arcpy.GetParameterInfo()

    def initializeParameters(self):
        # Customize parameter properties. This method gets called when the
        # tool is opened.
        for param in self.params:
            if param.name == "outputCoordinateSystem":
                param.value = arcpy.SpatialReference(2230)
        return

 but it didn't work out.

Could you, please, help me?

0 Kudos
1 Reply
HaydenWelch
MVP Regular Contributor

Your parameter name is the Name field. that is not 'outputCoordinateSystem' in your screenshot, but 'output_feature...'

 

You can also just manually set the environment variable using arcpy.env:

import arcpy

...
def main():
    arcpy.env.outputCoordinateSystem = arcpy.SpatialReference(2230)
    ...