<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic c# custom geoprocessing function tool - how to populate a polyline output parameter? in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/c-custom-geoprocessing-function-tool-how-to/m-p/533782#M17739</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm at 10.1SP1 with VS2010.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In my tool's ParameterInfo property I create an output parameter of type GPLineTypeClass.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then in the Execute() method I do work that creates an IPolyline that I want to stuff into that parameter.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PROBLEM 1: Using the GPUtilities.MakeGPValueFromObject(myIPolyline) method to get an IGPValue causes an E_FAIL COM error&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So I tried this instead:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;IGPLine2 outValue = new GPLineClass();
outValue.Polyline = myIPolyline;
gpUtils.PackGPValue((IGPValue)outValue, outputParam);&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PROBLEM 2: But I get an invalid cast exception on that first line - GPLineClass cannot be cast to IGPLine2. What! &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//002n0000006m000000" rel="nofollow noopener noreferrer" target="_blank"&gt;Documentation &lt;/A&gt;&lt;SPAN&gt;says this class implements this interface.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;SO - what is the secret sauce to stuff an IPolyline into an output parameter's value?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 23:12:09 GMT</pubDate>
    <dc:creator>markcheyne</dc:creator>
    <dc:date>2021-12-11T23:12:09Z</dc:date>
    <item>
      <title>c# custom geoprocessing function tool - how to populate a polyline output parameter?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/c-custom-geoprocessing-function-tool-how-to/m-p/533782#M17739</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm at 10.1SP1 with VS2010.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In my tool's ParameterInfo property I create an output parameter of type GPLineTypeClass.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then in the Execute() method I do work that creates an IPolyline that I want to stuff into that parameter.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PROBLEM 1: Using the GPUtilities.MakeGPValueFromObject(myIPolyline) method to get an IGPValue causes an E_FAIL COM error&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So I tried this instead:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;IGPLine2 outValue = new GPLineClass();
outValue.Polyline = myIPolyline;
gpUtils.PackGPValue((IGPValue)outValue, outputParam);&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PROBLEM 2: But I get an invalid cast exception on that first line - GPLineClass cannot be cast to IGPLine2. What! &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//002n0000006m000000" rel="nofollow noopener noreferrer" target="_blank"&gt;Documentation &lt;/A&gt;&lt;SPAN&gt;says this class implements this interface.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;SO - what is the secret sauce to stuff an IPolyline into an output parameter's value?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:12:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/c-custom-geoprocessing-function-tool-how-to/m-p/533782#M17739</guid>
      <dc:creator>markcheyne</dc:creator>
      <dc:date>2021-12-11T23:12:09Z</dc:date>
    </item>
  </channel>
</rss>

