<p dir="ltr">Out parameters are returned from the method as part of a tuple (if there is a return value already it will be in the tulle as the second item)</p>
<br><div class="gmail_quote"><div dir="ltr">On Sat, Jan 30, 2016, 07:38 Djordje Spasic via Ironpython-users <<a href="mailto:ironpython-users@python.org">ironpython-users@python.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="color:#000;background-color:#fff;font-family:verdana,helvetica,sans-serif;font-size:13px"><div dir="ltr">Thank you Stéphane!!<br><br>That solved the problem!</div><div dir="ltr"><br></div><div dir="ltr">Do you mind if I ask another question?</div><div dir="ltr">Right now I am trying to call another method: <a href="http://www.mapwindow.org/documentation/mapwingis4.8/class_shape.html#a25b160700f4c07dd86104c6675431ebf" target="_blank">FixUP</a>.</div><div dir="ltr">The problem with it, is that it requires a single "out" argument.<br><br>Here is how I tried to call it:</div><blockquote><div dir="ltr">MapWinGIS.ShapeClass.FixUp(shape)  # raises an error below<br></div></blockquote><div dir="ltr">But it raises this error message:</div><blockquote><div dir="ltr"><i>Message: expected ShapeClass, got __ComObject</i></div></blockquote><div dir="ltr">The same happens if I call it like so:</div><blockquote><div dir="ltr">shape.FixUp()</div></blockquote><div dir="ltr">The <i>__ComObject </i>in this case is <i>shape</i> variable. Any object I get, has this kind of type. <br></div><div dir="ltr">Is there a way to somehow cast the <i>shape</i> to <i>MapWinGIS.ShapeClass</i> type?</div><div dir="ltr">I tried this:</div><blockquote><div dir="ltr">shapeCast = clr.Reference[MapWinGIS.ShapeClass](shape)  # raises the same upper error on this line<br></div></blockquote><div dir="ltr">But the same upper message appears (<i>"expected ShapeClass, got __ComObject</i>")<br></div><div dir="ltr"><br></div><div dir="ltr">Any advice on how to supply the upper "out" argument to "FixUp" method?</div><div dir="ltr">Or maybe how to cast the <i>shape</i> to <i>MapWinGIS.ShapeClass</i> type?</div><div dir="ltr"><br></div><div><span>Thank you.<br><br>Djordje Spasic</span></div> <div><br><br></div><div style="display:block">  <div style="font-family:verdana,helvetica,sans-serif;font-size:13px"> <div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"> <div dir="ltr"> <font size="2" face="Arial"> <hr size="1"> <b><span style="font-weight:bold">From:</span></b> Stéphane Lozier <<a href="mailto:stephane.lozier@gmail.com" target="_blank">stephane.lozier@gmail.com</a>><br> <b><span style="font-weight:bold">To:</span></b> Djordje Spasic <<a href="mailto:issworld2000@yahoo.com" target="_blank">issworld2000@yahoo.com</a>> <br><b><span style="font-weight:bold">Cc:</span></b> "<a href="mailto:ironpython-users@python.org" target="_blank">ironpython-users@python.org</a>" <<a href="mailto:ironpython-users@python.org" target="_blank">ironpython-users@python.org</a>><br> <b><span style="font-weight:bold">Sent:</span></b> Friday, January 29, 2016 9:02 PM<br> <b><span style="font-weight:bold">Subject:</span></b> Re: [Ironpython-users] Cannot create instances of that class because it is abstract<br> </font> </div> <div><br><div><div><div dir="ltr"><div>I can't say I really know what's going on, but you could try using unbound class instance methods (see <a rel="nofollow" shape="rect" href="http://ironpython.net/documentation/dotnet/dotnet.html#using-unbound-class-instance-methods" target="_blank">http://ironpython.net/documentation/dotnet/dotnet.html#using-unbound-class-instance-methods</a>).<br clear="none"></div><div><br clear="none">For example:<br clear="none"></div>MapWinGIS.Shapefile.Open(sf, shpfilename, None)<br clear="none"></div><div><div><br clear="none"><div>On Fri, Jan 29, 2016 at 11:55 AM, Djordje Spasic <span dir="ltr"><<a rel="nofollow" shape="rect" href="mailto:issworld2000@yahoo.com" target="_blank">issworld2000@yahoo.com</a>></span> wrote:<br clear="none"><blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="color:#000;background-color:#fff;font-family:verdana,helvetica,sans-serif;font-size:13px"><div><div><div style="color:#000;background-color:#fff;font-family:verdana,helvetica,sans-serif;font-size:13px"><div><span></span></div><div><div>Thank you for the explanation Stéphane.</div><div><br clear="none"></div></div><div dir="ltr">When I use MapWinGIS.ShapefileClass() instead of MapWinGIS.Shapefile():</div><div dir="ltr"><br clear="none"></div><div dir="ltr">    import clr<br clear="none">   <br clear="none">    clr.AddReferenceToFileAndPath("C:/mapwindow_dlls/Interop.MapWinGIS.dll")<br clear="none"><br clear="none">    import MapWinGIS<br clear="none">   <br clear="none">    sf = MapWinGIS.<b>ShapefileClass</b>()<br clear="none">    shpfilename = "C:/example.shp"<br clear="none">    sf.Open(shpfilename, None)  # raises Error<br clear="none"></div><div dir="ltr"><br clear="none"></div><div><div>It raises an error:</div><div><blockquote><div dir="ltr"><i>Could not convert argument 0 for call to Open.</i></div></blockquote><div dir="ltr"><span><span>​I googled a couple of times, and found one place where the same issue has emerged: <a rel="nofollow" shape="rect" href="http://stackoverflow.com/questions/2296714/ironruby-cannot-call-method-on-a-com-object-with-one-or-more-arguments" target="_blank">here on stackoverflow</a>.​<br clear="none">​Stackoverflow issue is actually not related with ironpython, but with ironruby. The author states that the solution is to supply the CLR string as an argument to "Open" function, instead of regular ruby string. I tried that replicating that in ironpython:<br clear="none"></span></span></div><blockquote><div dir="ltr"><span><span></span></span><span><span>shpfilename = clr.Reference[System.String]("c:/example.shp")</span></span></div></blockquote><div dir="ltr"><span><span>But again the upper error message, did not go away.</span></span><span></span></div><div dir="ltr"><br clear="none"></div><div dir="ltr">Further googling found that this kind of issues may happen when trying <a rel="nofollow" shape="rect" href="http://stackoverflow.com/questions/8529313/how-do-i-call-a-vb6-com-object-from-c-sharp-with-dynamic-when-it-has-a-ref-param" target="_blank">to call methods in .NET from "<i>Interop COM objects</i>"</a>. But only if that method has "<i>ref parameters</i>". Which <i>Open</i> method does not. Here is the signature of the <i>Open</i> method:</div><div dir="ltr"><br clear="none"></div><blockquote><div dir="ltr">Help on method-descriptor Open Open(...)<br clear="none">    Open(self: ShapefileClass, ShapefileName: str, cBack: Callback) -> bool <br clear="none"><br clear="none">// MapWinGIS.ShapefileClass<br clear="none">[DispId(11)]<br clear="none">[MethodImpl(MethodImplOptions.InternalCall)]<br clear="none">public virtual extern bool Open([MarshalAs(UnmanagedType.BStr)] [In] string ShapefileName, [MarshalAs(UnmanagedType.Interface)] [In] ICallback cBack = null);</div></blockquote><div dir="ltr"><br clear="none">I would be very grateful for any kind of advice Stéphane.<br clear="none"><br clear="none">Kind regards,<br clear="none"></div><div dir="ltr">Djordje Spasic<br clear="none"></div><div dir="ltr"><i><br clear="none"></i></div></div><br clear="none"></div><div></div></div></div></div><div>  <div style="font-family:verdana,helvetica,sans-serif;font-size:13px"> <div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"> <div dir="ltr"> <font size="2" face="Arial"> </font><hr size="1"> <b><span style="font-weight:bold">From:</span></b> Stéphane Lozier <<a rel="nofollow" shape="rect" href="mailto:stephane.lozier@gmail.com" target="_blank">stephane.lozier@gmail.com</a>><br clear="none"> <b><span style="font-weight:bold">To:</span></b> Djordje Spasic <<a rel="nofollow" shape="rect" href="mailto:issworld2000@yahoo.com" target="_blank">issworld2000@yahoo.com</a>> <br clear="none"><b><span style="font-weight:bold">Cc:</span></b> "<a rel="nofollow" shape="rect" href="mailto:ironpython-users@python.org" target="_blank">ironpython-users@python.org</a>" <<a rel="nofollow" shape="rect" href="mailto:ironpython-users@python.org" target="_blank">ironpython-users@python.org</a>><br clear="none"> <b><span style="font-weight:bold">Sent:</span></b> Friday, January 29, 2016 5:24 PM<br clear="none"> <b><span style="font-weight:bold">Subject:</span></b> Re: [Ironpython-users] Cannot create instances of that class because it is abstract<br clear="none">  </div> <div><br clear="none"><div><div><div dir="ltr"><div>Shapefile is an interface with a CoClassAttribute to ShapefileClass (which means when you do new Shapefile() in C# it creates an instance of ShapefileClass). I have no idea what the correct behaviour for IronPython should be, but in this case MapWinGIS.Shapefile gives you the interface.<br clear="none"><br clear="none"></div>You could try MapWinGIS.ShapefileClass() instead of MapWinGIS.Shapefile().<br clear="none"><br clear="none"><br clear="none"></div><div><br clear="none"><div>On Mon, Jan 25, 2016 at 11:03 AM, Djordje Spasic via Ironpython-users <span dir="ltr"><<a rel="nofollow" shape="rect" href="mailto:ironpython-users@python.org" target="_blank">ironpython-users@python.org</a>></span> wrote:<br clear="none"><blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div style="color:#000;background-color:#fff;font-family:verdana,helvetica,sans-serif;font-size:13px"><div>Hello,<br clear="none"><br clear="none">I am trying to call a specific method ("Open") from the .NET assembly.</div><div dir="ltr">The .NET assembly along with all other .dlls and necessary files, can be downloaded <a rel="nofollow" shape="rect" href="https://mapwindow4.codeplex.com/releases/view/110244" target="_blank">from here</a>. It's free an open source project: MapWindow.</div><div dir="ltr"><br clear="none"></div><div dir="ltr">In their <a rel="nofollow" shape="rect" href="http://www.mapwindow.org/documentation/mapwingis4.9/examples.html" target="_blank">examples page</a>, by loading the <i>Interop.MapWinGIS.dll</i> file, they call the <i>MapWinGIS.</i><span><i>Shapefile.Open()</i> method like so:</span></div><div dir="ltr"><br clear="none"></div><blockquote><div dir="ltr"><span><span>using MapWinGIS;</span></span></div><div dir="ltr"><br clear="none"><span><span></span></span></div><div dir="ltr"><span><span>string </span></span><span><span>shpfilename = "</span></span><span><span>C:/example.shp";<br clear="none"></span></span></div><div dir="ltr"><span><span>Shapefile sf = new Shapefile();<br clear="none">if (sf.<b>Open</b>(</span></span><span><span>shpfilename, null))<br clear="none">{<br clear="none">}</span></span><span></span><b><br clear="none"></b></div></blockquote><div><br clear="none"></div><div>However, when I try the same thing in ironpython:</div><div><br clear="none"></div><div dir="ltr">    import clr<br clear="none">    import os<br clear="none">    <br clear="none">    shpfilename = "C:/example.shp"<br clear="none">    dllsfilename = "C:/mapwindow_dlls"<br clear="none">    <br clear="none">    clr.AddReferenceToFileAndPath(os.path.join(dllsfilename, "Interop.MapWinGIS.dll"))<br clear="none">    print "Interop.MapWinGIS.dll loaded: ", "Interop.MapWinGIS" in [assembly.GetName().Name for assembly in clr.References]  # prints: True<br clear="none">    import MapWinGIS<br clear="none">    <br clear="none">    sf = MapWinGIS.Shapefile()  # raises Error<br clear="none">    sf.<b>Open</b>(shpfilename, None)<br clear="none"></div><div><br clear="none"></div><div><br clear="none"></div><div dir="ltr">I am getting an error message:</div><div dir="ltr"><br clear="none"></div><div dir="ltr"><i>   "Message: Cannot create instances of Shapefile because it is abstract"</i></div><div dir="ltr"><span></span><span><br clear="none">Why is this happening?</span></div><div dir="ltr"><br clear="none"><span></span></div><div dir="ltr">I contacted the author of the project, but couldn't solve the issue.</div><div dir="ltr"><br clear="none"></div><div dir="ltr">Any kind of advice would be helpful.</div><div dir="ltr"><br clear="none"></div><div dir="ltr">Kind regards,<br clear="none">Djordje Spasic<br clear="none"><span></span></div><div dir="ltr"><span></span><br clear="none"></div></div></div></div><br clear="none">_______________________________________________<br clear="none">
Ironpython-users mailing list<br clear="none">
<a rel="nofollow" shape="rect" href="mailto:Ironpython-users@python.org" target="_blank">Ironpython-users@python.org</a><br clear="none">
<a rel="nofollow" shape="rect" href="https://mail.python.org/mailman/listinfo/ironpython-users" target="_blank">https://mail.python.org/mailman/listinfo/ironpython-users</a><br clear="none">
<br clear="none"></blockquote></div><br clear="none"></div></div></div><br clear="none"><br clear="none"></div> </div> </div>  </div></div></div></blockquote></div><br clear="none"></div></div></div></div><br><br></div> </div> </div>  </div></div></div>_______________________________________________<br>
Ironpython-users mailing list<br>
<a href="mailto:Ironpython-users@python.org" target="_blank">Ironpython-users@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/ironpython-users" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/ironpython-users</a><br>
</blockquote></div>