Forum: Ruby Win32ole question

6ff7cc79a09836e7930763a9d8b6ba9a?d=identicon&s=25 Dominic S. (dominic_s)
on 2014-08-09 18:09
(Received via mailing list)
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
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-08-09 21:45
Have you tried writing your own method to explicitly create the base
object, and then checking for nil in your own code and using that
method, rather than calling the non-working method?
E97181961afa48102e3a28daab69b904?d=identicon&s=25 MasakiSuketa (Guest)
on 2014-08-10 06:00
(Received via mailing list)
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
6ff7cc79a09836e7930763a9d8b6ba9a?d=identicon&s=25 Dominic S. (dominic_s)
on 2014-08-18 16:17
(Received via mailing list)
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>
E97181961afa48102e3a28daab69b904?d=identicon&s=25 MasakiSuketa (Guest)
on 2014-08-22 09:55
(Received via mailing list)
On Mon, Aug 18, 2014 at 08:16:21AM -0600, Dominic Sisneros wrote:

> > type Element. When I pass in nil in ruby it doesn't work because it is
> >   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
6ff7cc79a09836e7930763a9d8b6ba9a?d=identicon&s=25 Dominic S. (dominic_s)
on 2014-08-22 16:44
(Received via mailing list)
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>
E97181961afa48102e3a28daab69b904?d=identicon&s=25 MasakiSuketa (Guest)
on 2014-08-22 17:37
(Received via mailing list)
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
>

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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.