<html><head></head><body><div style="color:#000; background-color:#fff; font-family:verdana, helvetica, sans-serif;font-size:13px"><div id="yui_3_16_0_1_1454160152224_16724" dir="ltr">Thank you Stéphane!!<br><br>That solved the problem!</div><div id="yui_3_16_0_1_1454160152224_16748" dir="ltr"><br></div><div id="yui_3_16_0_1_1454160152224_16760" dir="ltr">Do you mind if I ask another question?</div><div id="yui_3_16_0_1_1454160152224_16759" dir="ltr">Right now I am trying to call another method: <a id="yui_3_16_0_1_1454160152224_17075" class="edited-link-editor" href="http://www.mapwindow.org/documentation/mapwingis4.8/class_shape.html#a25b160700f4c07dd86104c6675431ebf">FixUP</a>.</div><div id="yui_3_16_0_1_1454160152224_17080" 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 id="yui_3_16_0_1_1454160152224_17493"><div id="yui_3_16_0_1_1454160152224_17138" dir="ltr">MapWinGIS.ShapeClass.FixUp(shape)  # raises an error below<br></div></blockquote><div id="yui_3_16_0_1_1454160152224_17244" dir="ltr">But it raises this error message:</div><blockquote id="yui_3_16_0_1_1454160152224_17476"><div id="yui_3_16_0_1_1454160152224_17260" dir="ltr"><i id="yui_3_16_0_1_1454160152224_17544">Message: expected ShapeClass, got __ComObject</i></div></blockquote><div id="yui_3_16_0_1_1454160152224_17297" dir="ltr">The same happens if I call it like so:</div><blockquote id="yui_3_16_0_1_1454160152224_17445"><div id="yui_3_16_0_1_1454160152224_17285" dir="ltr">shape.FixUp()</div></blockquote><div id="yui_3_16_0_1_1454160152224_17323" dir="ltr">The <i>__ComObject </i>in this case is <i id="yui_3_16_0_1_1454160152224_18009">shape</i> variable. Any object I get, has this kind of type. <br></div><div id="yui_3_16_0_1_1454160152224_17400" dir="ltr">Is there a way to somehow cast the <i id="yui_3_16_0_1_1454160152224_18184">shape</i> to <i id="yui_3_16_0_1_1454160152224_17972">MapWinGIS.ShapeClass</i> type?</div><div id="yui_3_16_0_1_1454160152224_17879" dir="ltr">I tried this:</div><blockquote id="yui_3_16_0_1_1454160152224_17983"><div id="yui_3_16_0_1_1454160152224_17903" dir="ltr">shapeCast = clr.Reference[MapWinGIS.ShapeClass](shape)  # raises the same upper error on this line<br></div></blockquote><div id="yui_3_16_0_1_1454160152224_17973" dir="ltr">But the same upper message appears (<i class="" id="yui_3_16_0_1_1454160152224_17544">"expected ShapeClass, got __ComObject</i>")<br></div><div id="yui_3_16_0_1_1454160152224_17867" dir="ltr"><br></div><div id="yui_3_16_0_1_1454160152224_17399" dir="ltr">Any advice on how to supply the upper "out" argument to "FixUp" method?</div><div id="yui_3_16_0_1_1454160152224_18036" dir="ltr">Or maybe how to cast the <i>shape</i> to <i class="" id="yui_3_16_0_1_1454160152224_17972">MapWinGIS.ShapeClass</i> type?</div><div id="yui_3_16_0_1_1454160152224_17259" dir="ltr"><br></div><div id="yui_3_16_0_1_1454160152224_16553"><span>Thank you.<br><br>Djordje Spasic</span></div> <div id="yui_3_16_0_1_1454160152224_16481" class="qtdSeparateBR"><br><br></div><div style="display: block;" id="yui_3_16_0_1_1454160152224_16495" class="yahoo_quoted">  <div id="yui_3_16_0_1_1454160152224_16494" style="font-family: verdana, helvetica, sans-serif; font-size: 13px;"> <div id="yui_3_16_0_1_1454160152224_16493" style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div id="yui_3_16_0_1_1454160152224_16492" dir="ltr"> <font id="yui_3_16_0_1_1454160152224_16496" size="2" face="Arial"> <hr id="yui_3_16_0_1_1454160152224_16720" size="1"> <b><span style="font-weight:bold;">From:</span></b> Stéphane Lozier <stephane.lozier@gmail.com><br> <b><span style="font-weight: bold;">To:</span></b> Djordje Spasic <issworld2000@yahoo.com> <br><b><span style="font-weight: bold;">Cc:</span></b> "ironpython-users@python.org" <ironpython-users@python.org><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 id="yui_3_16_0_1_1454160152224_16521" class="y_msg_container"><br><div id="yiv4256678844"><div id="yui_3_16_0_1_1454160152224_16524"><div id="yui_3_16_0_1_1454160152224_16523" dir="ltr"><div id="yui_3_16_0_1_1454160152224_16522">I can't say I really know what's going on, but you could try using unbound class instance methods (see <a id="yui_3_16_0_1_1454160152224_16963" rel="nofollow" shape="rect" target="_blank" href="http://ironpython.net/documentation/dotnet/dotnet.html#using-unbound-class-instance-methods">http://ironpython.net/documentation/dotnet/dotnet.html#using-unbound-class-instance-methods</a>).<br clear="none"></div><div id="yui_3_16_0_1_1454160152224_16702"><br clear="none">For example:<br clear="none"></div>MapWinGIS.Shapefile.Open(sf, shpfilename, None)<br clear="none"></div><div class="yiv4256678844yqt4418281305" id="yiv4256678844yqt09494"><div id="yui_3_16_0_1_1454160152224_17582" class="yiv4256678844gmail_extra"><br clear="none"><div id="yui_3_16_0_1_1454160152224_17584" class="yiv4256678844gmail_quote">On Fri, Jan 29, 2016 at 11:55 AM, Djordje Spasic <span dir="ltr"><<a rel="nofollow" shape="rect" ymailto="mailto:issworld2000@yahoo.com" target="_blank" href="mailto:issworld2000@yahoo.com">issworld2000@yahoo.com</a>></span> wrote:<br clear="none"><blockquote id="yui_3_16_0_1_1454160152224_17591" class="yiv4256678844gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div id="yui_3_16_0_1_1454160152224_17590"><div id="yui_3_16_0_1_1454160152224_17589" style="color:#000;background-color:#fff;font-family:verdana, helvetica, sans-serif;font-size:13px;"><div id="yui_3_16_0_1_1454160152224_17588"><div id="yui_3_16_0_1_1454160152224_17587"><div id="yui_3_16_0_1_1454160152224_17586" 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 id="yui_3_16_0_1_1454160152224_17615" dir="ltr">When I use MapWinGIS.ShapefileClass() instead of MapWinGIS.Shapefile():</div><div dir="ltr"><br clear="none"></div><div id="yui_3_16_0_1_1454160152224_17585" 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 id="yui_3_16_0_1_1454160152224_17594">ShapefileClass</b>()<br clear="none">    shpfilename = "C:/example.shp"<br clear="none">    sf.Open(shpfilename, None)  # raises Error<br clear="none"></div><div id="yui_3_16_0_1_1454160152224_17613" dir="ltr"><br clear="none"></div><div id="yui_3_16_0_1_1454160152224_17599"><div>It raises an error:</div><div id="yui_3_16_0_1_1454160152224_17598"><blockquote><div dir="ltr"><i>Could not convert argument 0 for call to Open.</i></div></blockquote><div id="yui_3_16_0_1_1454160152224_17603" dir="ltr"><span id="yui_3_16_0_1_1454160152224_17602"><span id="yui_3_16_0_1_1454160152224_17601">​I googled a couple of times, and found one place where the same issue has emerged: <a rel="nofollow" shape="rect" target="_blank" href="http://stackoverflow.com/questions/2296714/ironruby-cannot-call-method-on-a-com-object-with-one-or-more-arguments">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 id="yui_3_16_0_1_1454160152224_17611"><div id="yui_3_16_0_1_1454160152224_17610" dir="ltr"><span><span></span></span><span id="yui_3_16_0_1_1454160152224_17609"><span id="yui_3_16_0_1_1454160152224_17608">shpfilename = clr.Reference[System.String]("c:/example.shp")</span></span></div></blockquote><div id="yui_3_16_0_1_1454160152224_17597" dir="ltr"><span id="yui_3_16_0_1_1454160152224_17596"><span id="yui_3_16_0_1_1454160152224_17595">But again the upper error message, did not go away.</span></span><span></span></div><div id="yui_3_16_0_1_1454160152224_17604" dir="ltr"><br clear="none"></div><div id="yui_3_16_0_1_1454160152224_17605" dir="ltr">Further googling found that this kind of issues may happen when trying <a id="yui_3_16_0_1_1454160152224_17607" rel="nofollow" shape="rect" target="_blank" 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">to call methods in .NET from "<i id="yui_3_16_0_1_1454160152224_17606">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" ymailto="mailto:stephane.lozier@gmail.com" target="_blank" href="mailto:stephane.lozier@gmail.com">stephane.lozier@gmail.com</a>><br clear="none"> <b><span style="font-weight:bold;">To:</span></b> Djordje Spasic <<a rel="nofollow" shape="rect" ymailto="mailto:issworld2000@yahoo.com" target="_blank" href="mailto:issworld2000@yahoo.com">issworld2000@yahoo.com</a>> <br clear="none"><b><span style="font-weight:bold;">Cc:</span></b> "<a rel="nofollow" shape="rect" ymailto="mailto:ironpython-users@python.org" target="_blank" href="mailto:ironpython-users@python.org">ironpython-users@python.org</a>" <<a rel="nofollow" shape="rect" ymailto="mailto:ironpython-users@python.org" target="_blank" href="mailto:ironpython-users@python.org">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" ymailto="mailto:ironpython-users@python.org" target="_blank" href="mailto:ironpython-users@python.org">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" target="_blank" href="https://mapwindow4.codeplex.com/releases/view/110244">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" target="_blank" href="http://www.mapwindow.org/documentation/mapwingis4.9/examples.html">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" ymailto="mailto:Ironpython-users@python.org" target="_blank" href="mailto:Ironpython-users@python.org">Ironpython-users@python.org</a><br clear="none">
<a rel="nofollow" shape="rect" target="_blank" href="https://mail.python.org/mailman/listinfo/ironpython-users">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></body></html>