ruby / ruby/win32ole

have an implicit conversion to_ole

Open
#28 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
16
Forks
8
Avg merge
6h 42m
Merged PRs (30d)
1

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the WIN32OLE method-call argument conversion path used by calls such as GetPoint and AddLine. Compare the requested to_ole behavior with Ruby's File.open to_path convention. Done means objects such as Point3d can supply OLE-compatible arguments without wrapper methods, with behavior covered by relevant WIN32OLE tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
desktop, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.