Win32ole question

I have a function that accepts either a Nothing in VBA or a Template of type Element. When I pass in nil in ruby it doesn't work because it is expecting a type of element. How can I correctly pass a non value that gets accepted. This iron python guy explains it better

I have the exact same problem as this guy
http://ironpython-users.gmang.org/2012-January/015551.html

···

----------
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)] NIn] 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

Dominic

Hello

I have a function that accepts either a Nothing in VBA or a Template of type Element. When I pass in nil in ruby it doesn't work because it is expecting a type of element. How can I correctly pass a non value that gets accepted. This iron python guy explains it better

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?

I'm not sure it works or not, but try WIN32OLE_VARIANT object instead of nil.
  nilobj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_VARIANT)
or
  nilobj = WIN32OLE_VARIANT::Nothing
and call CreateLineElement2
  object.CreateLineElement2 (nilobj, startpoint, endpoint)

  Regards,
  Masaki Suketa

···

On Sat, Aug 09, 2014 at 10:09:30AM -0600, Dominic Sisneros wrote:

Masaki Suketa,

Thank you for your prompt reply. It is still not working with either of
these variations. How would I send a VT_ERROR with a value of
DISP_E_PARAMNOTFOUND

psuedo code like the following

WIN32OLE::VARIANT.new(DISP_E_PARAMNOTFOUND, WIN32OLE::VARIANT::VT_ERROR)

···

On Sat, Aug 9, 2014 at 9:59 PM, MasakiSuketa <masaki.suketa@nifty.ne.jp> wrote:

Hello

On Sat, Aug 09, 2014 at 10:09:30AM -0600, Dominic Sisneros wrote:
> I have a function that accepts either a Nothing in VBA or a Template of
type Element. When I pass in nil in ruby it doesn't work because it is
expecting a type of element. How can I correctly pass a non value that gets
accepted. This iron python guy explains it better

> 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?

I'm not sure it works or not, but try WIN32OLE_VARIANT object instead of
nil.
  nilobj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_VARIANT)
or
  nilobj = WIN32OLE_VARIANT::Nothing
and call CreateLineElement2
  object.CreateLineElement2 (nilobj, startpoint, endpoint)

  Regards,
  Masaki Suketa

Have you tried WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_ERROR)
without setting DISP_E_PARAMNOTFOUND?

  obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_ERROR)
  object.CreateLineElement2 (obj, startpoint, endpoint)

  Regards,
  Masaki Suketa

···

On Mon, Aug 18, 2014 at 08:16:21AM -0600, Dominic Sisneros wrote:

Thank you for your prompt reply. It is still not working with either of
these variations. How would I send a VT_ERROR with a value of
DISP_E_PARAMNOTFOUND

psuedo code like the following

WIN32OLE::VARIANT.new(DISP_E_PARAMNOTFOUND, WIN32OLE::VARIANT::VT_ERROR)

> > I have a function that accepts either a Nothing in VBA or a Template of
> type Element. When I pass in nil in ruby it doesn't work because it is
> expecting a type of element. How can I correctly pass a non value that gets
> accepted. This iron python guy explains it better
>
> > 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?
>
> I'm not sure it works or not, but try WIN32OLE_VARIANT object instead of
> nil.
> nilobj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_VARIANT)
> or
> nilobj = WIN32OLE_VARIANT::Nothing
> and call CreateLineElement2
> object.CreateLineElement2 (nilobj, startpoint, endpoint)

Yes, I tried that. It sets the obj to a WIN32OLE_VARIANT of type 10 with
value 0 of type Fixnum but when I call the CreateLineElement2 method
it gives me the type mismatch error

···

On Fri, Aug 22, 2014 at 1:53 AM, MasakiSuketa <masaki.suketa@nifty.ne.jp> wrote:

On Mon, Aug 18, 2014 at 08:16:21AM -0600, Dominic Sisneros wrote:

> Thank you for your prompt reply. It is still not working with either of
> these variations. How would I send a VT_ERROR with a value of
> DISP_E_PARAMNOTFOUND
>
> psuedo code like the following
>
> WIN32OLE::VARIANT.new(DISP_E_PARAMNOTFOUND, WIN32OLE::VARIANT::VT_ERROR)
>
>
> > > I have a function that accepts either a Nothing in VBA or a Template
of
> > type Element. When I pass in nil in ruby it doesn't work because it is
> > expecting a type of element. How can I correctly pass a non value that
gets
> > accepted. This iron python guy explains it better
> >
> > > 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?
> >
> > I'm not sure it works or not, but try WIN32OLE_VARIANT object instead
of
> > nil.
> > nilobj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_VARIANT)
> > or
> > nilobj = WIN32OLE_VARIANT::Nothing
> > and call CreateLineElement2
> > object.CreateLineElement2 (nilobj, startpoint, endpoint)

Have you tried WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_ERROR)
without setting DISP_E_PARAMNOTFOUND?

  obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_ERROR)
  object.CreateLineElement2 (obj, startpoint, endpoint)

  Regards,
  Masaki Suketa

Can you call CreateLineElement2 method from VBScript(not VB.NET)?
If you can't call it from VBScript, then you can not call from
Ruby(Win32OLE).

Or, maybe you could call the method by using WIN32OLE_RECORD object.
WIN32OLE_RECORD class is supported in Ruby 2.2.0-dev(r47027) or later.

Regards,
Masaki Suketa

···

On Fri, Aug 22, 2014 at 08:43:57AM -0600, Dominic Sisneros wrote:

Yes, I tried that. It sets the obj to a WIN32OLE_VARIANT of type 10 with
value 0 of type Fixnum but when I call the CreateLineElement2 method
it gives me the type mismatch error