[Ironpython-users] COM Interop argument convert error

Jeff Hardy jdhardy at gmail.com
Wed Jan 25 07:45:23 CET 2012


Check out http://ironpython.net/documentation/dotnet/dotnet.html#ref-and-out-parameters
- IronPython treats ref/out parameters a bit differently than VBA
does.

- Jeff

On Tue, Jan 24, 2012 at 8:06 PM, Kamu <mr.kamu at gmail.com> wrote:
> Hi All,
>
> Having a problem passing 'None' to a COM Interop method that can
> accept 'Nothing' (in VBA)
>
> My code (with considerable snippage):
>
> t = System.Type.GetTypeFromProgID("MicroStationDGN.Application")
> self.ms = System.Activator.CreateInstance(t)
>
> elem = self.ms.CreateLineElement2(None, point3d1, point3d2)
>
> Now, I know that the point3d objects are working fine, and self.ms is
> working fine as it is part of a library I am putting together and they
> are working fine with other methods. How ever, I run it and get this
> error:
>
> E:\py>ipy titleblocknew.py
> Traceback (most recent call last):
>   File "titleblocknew.py", line 26, in <module>
>   File "E:\py\ustation.py", line 162, in create_line
> ValueError: Could not convert argument 2 for call to CreateLineElement2.
>
>
> ILSpy says this about the method:
>
> // Bentley.Interop.MicroStationDGN.Application
> [MethodImpl(4096)]
> [return: MarshalAs(28)]
> LineElement CreateLineElement2([MarshalAs(28)] [In] Element Template,
> [In] [Out] ref Point3d StartPoint, [In] [Out] ref Point3d EndPoint);
>
> ---
>
> MicroStation documentation says this:
>
> Set LineElement = object.CreateLineElement2 (Template, StartPoint, EndPoint)
>
> The CreateLineElement2 method syntax has these parts:
>
> Part Description
> object A valid object. (Application object)
> Template An Element expression. An existing element whose settings are
> used to initialize the new element. If Nothing, the new element's
> settings are initialized from MicroStation's active settings.
> StartPoint A Point3d expression.
> EndPoint A Point3d expression.
>
> ---
>
> My basic understanding is that it is trying to convert None into an
> 'Element' object, but is unable to do so. Is there a way around this?
>
> Thanks,
>
> Kamu
> _______________________________________________
> Ironpython-users mailing list
> Ironpython-users at python.org
> http://mail.python.org/mailman/listinfo/ironpython-users


More information about the Ironpython-users mailing list