You have to define an output parameter in the ParameterInfo array of your GP tool, then set the value of that output parameter in the Execute() method. I've included a small code sample below:
// This is the location where the parameters to the Function Tool are defined.
// This property returns an IArray of parameter objects (IGPParameter).
// These objects define the characteristics of the input and output parameters.
public IArray ParameterInfo
{
get
//Array to the hold the parameters
IArray parameters = new ArrayClass();
//Input DataType is GPStringType
IGPParameterEdit3 inputParameter = new GPParameterClass();
inputParameter.DataType = new GPStringTypeClass();
// Default Value object is GPString
inputParameter.Value = new GPStringClass();
// Set Input Parameter properties
inputParameter.Direction = esriGPParameterDirection.esriGPParameterDirectionInput;
inputParameter.DisplayName = "Station ID";
inputParameter.Name = "stationid";
inputParameter.ParameterType = esriGPParameterType.esriGPParameterTypeRequired;
parameters.Add(inputParameter);
//Out DataType is GPStringType
IGPParameterEdit3 outputParameter = new GPParameterClass();
outputParameter.DataType = new GPStringTypeClass();
outputParameter.Value = new GPStringClass();
// Set Output Parameter properties
outputParameter.Direction = esriGPParameterDirection.esriGPParameterDirectionOutput;
outputParameter.DisplayName = "Output";
outputParameter.Name = "output";
outputParameter.ParameterType = esriGPParameterType.esriGPParameterTypeDerived;
parameters.Add(outputParameter);
return parameters;
}
... and then
// Execute: Execute the function given the array of the parameters
public void Execute(IArray paramvalues, ITrackCancel trackcancel, IGPEnvironmentManager envMgr, IGPMessages message)
bool success = false;
// Get the first Input Parameter
IGPParameter inputParameter = (IGPParameter)paramvalues.get_Element(0);
// UnPackGPValue. This ensures you get the value either form the dataelement or GpVariable (ModelBuilder)
IGPValue inputValue = m_GPUtilities.UnpackGPValue(inputParameter);
// input station ID
string inputStringValue = inputValue.GetAsText();
if (!string.IsNullOrEmpty(inputStringValue))
success = true;
if (!success)
message.AddError(2, "An error occurred during the test.");
else
message.AddMessage("Test completed successfully!");
// Set the Output Parameter
IGPParameter outputParameter = (IGPParameter)paramvalues.get_Element(1);
IGPString outValue = new GPStringClass();
outValue.Value = "This is my output showing input value of '" + inputStringValue + "'";
m_GPUtilities.PackGPValue((IGPValue)outValue, outputParameter);
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.