Thursday, July 9, 2009

2 GP Functions That Make Life Easier

Here are two functions that make life easier for custom GP development. The find parameter value by the parameter name, return parameter type IGPValue. The second method is get parameter by name, which returns IGPParameter3. Parameter value by name allows you to retrieve

Get Parameter By Name

public IGPParameter3 GetParameterByName( IArray paramvalues, string name )
{
IGPParameter3 gpParameter;
for (int i = 0; i < paramvalues.Count; i++)
{
gpParameter = (IGPParameter3)paramvalues.get_Element( i );
if (gpParameter.Name.Equals( name, StringComparison.OrdinalIgnoreCase ))
return gpParameter;
}
return null;
}


Get Parameter Value By Name

public IGPValue GetParameterValueByName( IArray paramvalues, string name )
{
IGPUtilities2 gpUtils = new GPUtilitiesClass();
IGPParameter3 gpParameter;

for (int i = 0; i < paramvalues.Count; i++)
{
gpParameter = (IGPParameter3)paramvalues.get_Element( i );
if (gpParameter.Name.ToUpper() == name.ToUpper())
return gpUtils.UnpackGPValue( gpParameter );
}
return null;
}