WIN32OLE_RECORD and WIN32OLE_VARIANT

I have an array of WIN32OLE_RECORD objects

ole_pts = pts.map{|pt| app.to_ole_point3d(pt)}
=> [#<WIN32OLE_RECORD(Point3d) {"X"=>0.0, "Y"=>0.0, "Z"=>0.0}>,
#<WIN32OLE_RECORD(Point3d) {"X"=>10.0, "Y"=>0.0, "Z"=>0.0}>,
#<WIN32OLE_RECORD(Point3d) {"X"=>10.0, "Y"=>10.0, "Z"=>0.0}>,
#<WIN32OLE_RECORD(Point3d) {"X"=>0.0, "Y"=>10.0, "Z"=>0.0}>,
#<WIN32OLE_RECORD(Point3d) {"X"=>0.0, "Y"=>0.0, "Z"=>0.0}>]

When I try to convert it to a WIN32OLE_VARIANT array it gives an error

[80] pry(main)> obj = WIN32OLE_VARIANT.new(ole_pts)
TypeError: can not convert WIN32OLE_VARIANT from type WIN32OLE_RECORD

I think I need to convert it to a VARIANT ARRAY because I have the
following ole function - function signature from olegen.rb

# _LineElement CreateLineElement1
  # _Element arg0 --- Template [IN]
  # Point3d arg1 --- Vertices [IN/OUT]
  def CreateLineElement1(arg0, arg1)
    ret = _invoke(1610743981, [arg0, arg1], [VT_BYREF|VT_DISPATCH,
VT_BYREF|VT_ARRAY|VT_DISPATCH])
    @lastargs = WIN32OLE::ARGV
    ret
  end

when called it gives me a HRESULT error code:0x80020005 Type mismatch

Hmmm, I'm not sure,
Is ole_pts second argument of CreateLineElement1?
If so, How about calling CreateLineElement1(xxx, ole_pts)? (without
converting by WIN32OLE_VARIANT.new)

  Regards,
  Masaki Suketa

···

On Wed, Oct 23, 2019 at 03:13:33PM -0600, Dominic Sisneros wrote:

ole_pts = pts.map{|pt| app.to_ole_point3d(pt)}
=> [#<WIN32OLE_RECORD(Point3d) {"X"=>0.0, "Y"=>0.0, "Z"=>0.0}>,
#<WIN32OLE_RECORD(Point3d) {"X"=>10.0, "Y"=>0.0, "Z"=>0.0}>,
#<WIN32OLE_RECORD(Point3d) {"X"=>10.0, "Y"=>10.0, "Z"=>0.0}>,
#<WIN32OLE_RECORD(Point3d) {"X"=>0.0, "Y"=>10.0, "Z"=>0.0}>,
#<WIN32OLE_RECORD(Point3d) {"X"=>0.0, "Y"=>0.0, "Z"=>0.0}>]

When I try to convert it to a WIN32OLE_VARIANT array it gives an error

[80] pry(main)> obj = WIN32OLE_VARIANT.new(ole_pts)
TypeError: can not convert WIN32OLE_VARIANT from type WIN32OLE_RECORD

I think I need to convert it to a VARIANT ARRAY because I have the
following ole function - function signature from olegen.rb

# _LineElement CreateLineElement1
  # _Element arg0 --- Template [IN]
  # Point3d arg1 --- Vertices [IN/OUT]
  def CreateLineElement1(arg0, arg1)
    ret = _invoke(1610743981, [arg0, arg1], [VT_BYREF|VT_DISPATCH,
VT_BYREF|VT_ARRAY|VT_DISPATCH])
    @lastargs = WIN32OLE::ARGV
    ret
  end

I get a type mismatch

    19: def line_from_pts(pts, el = WIN32OLE_VARIANT::Nothing)
    20: ole_points = pts.map{ |pt| app.to_ole_point3d(pt) }
    21: ole = app.ole_obj.CreateLineElement1(el, ole_points)
    22: if ole
    23: add_element(ole)
    24: else
    25: binding.pry
    26: end
    27: rescue Exception => e
    28: binding.pry
=> 29: return nil
    30: end
[1] pry(#<Microstation::Model>)> e
=> #<WIN32OLERuntimeError: (in OLE method `CreateLineElement1': )
    OLE error code:0 in <Unknown>
      <No Description>
    HRESULT error code:0x80020005
      Type mismatch.>
[2] pry(#<Microstation::Model>)> ole_points
=> [#<WIN32OLE_RECORD(Point3d) {"X"=>0.0, "Y"=>0.0, "Z"=>0.0}>,
#<WIN32OLE_RECORD(Point3d) {"X"=>0.0, "Y"=>20.0, "Z"=>0.0}>,
#<WIN32OLE_RECORD(Point3d) {"X"=>20.0, "Y"=>20.0, "Z"=>0.0}>,
#<WIN32OLE_RECORD(Point3d) {"X"=>0.0, "Y"=>0.0, "Z"=>0.0}>]
[3] pry(#<Microstation::Model>)> el
=> #<WIN32OLE_VARIANT:0x000000000c00e3b0>

I have a similar function for drawing line from to points that works so the
element el of type WIN32OLE_VARIANT::Nothing is the correct type

this function works

   def line(p1,p2,el = WIN32OLE_VARIANT::Nothing)
      pt1 = app.to_ole_point3d(p1)
      pt2 = app.to_ole_point3d(p2)
      begin
        ole = app.ole_obj.CreateLineElement2(el,pt1,pt2)
      rescue Exception => ex
        binding.pry
        return nil
      end
      add_element(ole) if ole
    end

With this function signature from olegen.rb

# _LineElement CreateLineElement2
  # _Element arg0 --- Template [IN]
  # Point3d arg1 --- StartPoint [IN/OUT]
  # Point3d arg2 --- EndPoint [IN/OUT]
  def CreateLineElement2(arg0, arg1, arg2)
    ret = _invoke(1610743982, [arg0, arg1, arg2], [VT_BYREF|VT_DISPATCH,
VT_BYREF|VT_DISPATCH, VT_BYREF|VT_DISPATCH])
    @lastargs = WIN32OLE::ARGV
    ret
  end

···

On Thu, Oct 24, 2019 at 6:32 AM Masaki Suketa <masaki.suketa@nifty.ne.jp> wrote:

On Wed, Oct 23, 2019 at 03:13:33PM -0600, Dominic Sisneros wrote:
>
> ole_pts = pts.map{|pt| app.to_ole_point3d(pt)}
> => [#<WIN32OLE_RECORD(Point3d) {"X"=>0.0, "Y"=>0.0, "Z"=>0.0}>,
> #<WIN32OLE_RECORD(Point3d) {"X"=>10.0, "Y"=>0.0, "Z"=>0.0}>,
> #<WIN32OLE_RECORD(Point3d) {"X"=>10.0, "Y"=>10.0, "Z"=>0.0}>,
> #<WIN32OLE_RECORD(Point3d) {"X"=>0.0, "Y"=>10.0, "Z"=>0.0}>,
> #<WIN32OLE_RECORD(Point3d) {"X"=>0.0, "Y"=>0.0, "Z"=>0.0}>]
>
> When I try to convert it to a WIN32OLE_VARIANT array it gives an error
>
> [80] pry(main)> obj = WIN32OLE_VARIANT.new(ole_pts)
> TypeError: can not convert WIN32OLE_VARIANT from type WIN32OLE_RECORD
>
> I think I need to convert it to a VARIANT ARRAY because I have the
> following ole function - function signature from olegen.rb
>
> # _LineElement CreateLineElement1
> # _Element arg0 --- Template [IN]
> # Point3d arg1 --- Vertices [IN/OUT]
> def CreateLineElement1(arg0, arg1)
> ret = _invoke(1610743981, [arg0, arg1], [VT_BYREF|VT_DISPATCH,
> VT_BYREF|VT_ARRAY|VT_DISPATCH])
> @lastargs = WIN32OLE::ARGV
> ret
> end

Hmmm, I'm not sure,
Is ole_pts second argument of CreateLineElement1?
If so, How about calling CreateLineElement1(xxx, ole_pts)? (without
converting by WIN32OLE_VARIANT.new)

  Regards,
  Masaki Suketa

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>