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
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 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
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?
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
On Sat, Aug 09, 2014 at 10:09:30AM -0600, Dominic S. 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)
On Mon, Aug 18, 2014 at 08:16:21AM -0600, Dominic S. 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?
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 08:43:57AM -0600, Dominic S. 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 S.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.