WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

have an implicit conversion to_ole #28

@dsisnero

Description

@dsisnero

I am trying to automate Autocad. I have a Point3d class that I want to use in Autocad with WIN32OLE. There is a method that takes a optional input of Point - which is a Variant (three-element array of doubles) . There are other methods that also takes a Variant, three-element array of doubles.
--- Get Point Documentation

RetVal = object.GetPoint([Point [, Prompt]])
object
Type: [Utility](https://help.autodesk.com/view/OARX/2022/ENU/?guid=GUID-DE118C17-4567-48CF-8EFA-CABB52A27275)

The object this method applies to.

Point
Access: Input-only; optional

Type: Variant (three-element array of doubles)

The 3D WCS coordinates specifying the relative base point.

Prompt
Access: Input-only; optional

Type: Variant (string)

The text used to prompt the user for input.

Return Value (RetVal)
Type: Variant (three-element array of doubles)

I don't want to add wrapper methods for each method that takes a 3-element array of doubles

def get_point(prompt: "get_point", pt: nil)
      if pt
          array_pt = pt.to_ary.map{|val| val.to_f}
          t = WIN32OLE_VARIANT.array([3], WIN32OLE::VARIANT::VT_R8)
          t[0] = array_pt[0]
         t[1] = array_pt[1]
         t[2] = array_pt[3]
          ole_obj.GetPoint(t, prompt)
        else
           ole_obj.GetPoint(nil,prompt)
       end.
     
end

or ole_obj.AddLine(point, point)

What if there was a conversion method like to_path -> to_ole that would be called for the parameters for a WIN32OLE method call

class Point3d
def to_ole
   pt =WIN32OLE_VARIANT.array([3], WIN32OLE::VARIANT::VT_R8)
  pt[0] = x
  pt[1] = y
  pt[2] = z
end
end
// converts the points to float on initialization
mypoint = Point3d.new(0, 1, 2) 
ole_obj.GetPoint(nil, mypoint)

before calling the underlying method , this would call to_ole on mypoint similary to how File.open calls to_path

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions