[Ironpython-users] COM Interop argument convert error

Kamu mr.kamu at gmail.com
Wed Jan 25 15:15:59 CET 2012


I did a bit of playing around and I have instead of feeding the
argument a None, I fed the template argument an element that is
fetched through another COM method. This has caused the call to go
through with out any problems (so: the point3ds do not have to be
refs). However, I really do want to pass None to the template
argument.

I tried the following code:
template = clr.Reference[Element]()
template.Value = None
elem = self.ms.CreateLineElement2(template, point3d1, point3d2)

-------

No change. Still the same "cannot convert argument 2" error. I even
see that I cannot create an Element object at all:

TypeError: Cannot create instances of Element because it is abstract

Turns out that straight after the 1st line template is None due to
being unable to initialise the ref or some such.
I'm lost. In the Microstation VBA doc examples they dimension
variables to the type Element all the time.
Even still, all I really want to do at the time being is pass None as
the template. How do I go about doing this?

On Wed, Jan 25, 2012 at 2:45 PM, Jeff Hardy <jdhardy at gmail.com> wrote:
> 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