Loading newLISP.dll in Google SketchUp 7 Ruby problem

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Loading newLISP.dll in Google SketchUp 7 Ruby problem

Post by HPW »

I tried to load newLISP.dll on Google SketchUp 7 in the Ruby console.

I do:
I copy "Win32API.so" and the newLISP.dll to the Sketchup Plugins folder
(The library can be found in ruby distribution: \ruby\lib\ruby\1.8\i386-mswin32\Win32API.so)

In the ruby console in SketchUp:

Code: Select all

require 'Win32API'
true
newLISP = Win32API.new("newlisp.dll", "newlispEvalStr", ['P'], 'V')
Error: #<RuntimeError: (eval):131:in `initialize': LoadLibrary: newlisp.dll
>
(eval):131
Some doku here:
http://phrogz.net/ProgrammingRuby/lib_w ... l#Win32API
See: class Win32API < Object

This is a working code example:

Code: Select all

findWindow = Win32API.new("user32.dll", "FindWindow", ['P','P'], 'N') 
window_id = findWindow.call(0, sketchup_title) 
sendMessage = Win32API.new("user32.dll", "SendMessage", ['N','N','N','P'], 'N') 
sendMessage.call(window_id, 0x0010, 0, "") 
Not sure if I make a mistake with the calling parameters or what else cause the error.
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

After fiddeling a lot around I finally found the solution:

Code: Select all

require 'Win32API'
true
newLISP = Win32API.new("C:\\Program Files\\Google\\Google SketchUp 7\\Plugins\\newlisp.dll", "newlispEvalStr", ['P'], 'P')
#<Win32API>
newLISP.Call("(sys-info)")
(363 268435456 360 1 0 2048 6064 10003 70)
newLISP.Call("(setq a(+ 10 10))")
20
newLISP.Call("(setq b(+ a 10))")
30
This is a great new option.

Posted this news to:

http://www.sketchucation.com/forums/scf ... 80&t=18127
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Making slow progress with ruby calling after inspecting the exported functions from msvcrt-ruby18.dll:

Code: Select all

require 'Win32API'
true
newLISP = Win32API.new("C:\\Program Files\\Google\\Google SketchUp 7\\Plugins\\newlisp.dll", "newlispEvalStr", ['P'], 'P')
#<Win32API>
newLISP.Call("(import {C:\\Program Files\\Google\\Google SketchUp 7\\msvcrt-ruby18.dll} {rb_eval_string})")
rb_eval_string <1CF2F30>

newLISPret = newLISP.Call("(rb_eval_string {puts \"Ruby called from Lisp\"})")
Ruby called from Lisp
4

newLISP.Call("(rb_eval_string {VERSION})")
47157480
Not sure what the return-value 4 or 47157480 from rb_eval_string means.
Still searching to get values from ruby-calls back to newLISP.

Code: Select all

newLISPret = newLISP.Call("(setq rubyversion(get-string (rb_eval_string {VERSION})))")
"\007\004"
The ruby console shows normal:

Code: Select all

VERSION
1.8.0
Hans-Peter

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

47157480
perhaps the memory address of the string coming back?

m35
Posts: 171
Joined: Wed Feb 14, 2007 12:54 pm
Location: Carifornia

Post by m35 »

This is some neat stuff HPW. I use a little SU, although I try to keep Blender as my primary tool (all my scripts are in Blender). If SU ends up playing a bigger role, I may be back to see how this pans out. :)

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

perhaps the memory address of the string coming back?
Some ruby people told me that it is an ruby object-ID.
This seems a more complex thing.
I am considering to build a helper DLL with delphi using:
http://www.sourcepole.ch/2006/9/1/embed ... lix-delphi
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

For someone familar with C/C++ maybe this can help to get a similar newLISP function:

http://www.sourcepole.com/2004/1/21/embedding-ruby-in-c

The delphi version does currently only work from an EXE, so I am in trouble with an helper DLL.
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

After making a helper-DLL RubyCall.dll I get further progress:

Here the ruby console log:
require 'Win32API'
true
newLISP = Win32API.new("C:\\Program Files\\Google\\Google SketchUp 7\\Plugins\\newlisp.dll", "newlispEvalStr", ['P'], 'P')
#<Win32API>
newLISP.Call("(import {C:\\Program Files\\Google\\Google SketchUp 7\\RubyCall.dll} {CreateRuby})")
CreateRuby <499C1B4>

newLISP.Call("(import {C:\\Program Files\\Google\\Google SketchUp 7\\RubyCall.dll} {EvalRuby})")
EvalRuby <499C23C>

newLISP.Call("(get-string(CreateRuby \"\"))")
"Ruby interpreter loaded!"

newLISP.Call("(get-string(EvalRuby {name = Sketchup.app_name}))")
"Google SketchUp"

newLISP.Call("(import {C:\\Program Files\\Google\\Google SketchUp 7\\RubyCall.dll} {GetRubyOutput})")
GetRubyOutput <499C338>

newLISP.Call("(get-string(EvalRuby {puts \"Hello World!\";test = 2+2}))")
"4"

newLISP.Call("(get-string(GetRubyOutput \"\"))")
"Hello World!\r\n"
So now I get back all kind (types) of return-values and the accumulated consol-output form ruby's puts commands.
When it is finished I will add it to my newLISP extension page.
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Re: Loading newLISP.dll in Google SketchUp 7 Ruby problem

Post by HPW »

Hello,

After some more learning about ruby modules with my new pdSript-extension for Sketchup 7/8 I converted the newLISP extension also into a module so it gets its own namespace etc.

http://www.hpwsoft.de/anmeldung/html1/s ... chup2.html

From that link you can download the extension.

Hans-Peter
Last edited by HPW on Tue Jan 24, 2012 9:39 pm, edited 2 times in total.
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Re: Loading newLISP.dll in Google SketchUp 7 Ruby problem

Post by HPW »

Hello,

After more improvments/language support to the ruby-module of the newlisp extension for Sketchup 7/8 I upload a new 1.01 version to the above link.

Hans-Peter
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Re: Loading newLISP.dll in Google SketchUp 7 Ruby problem

Post by HPW »

Hello,

Finally I make a small website for the plugin:

http://www.hpwsoft.de/anmeldung/html1/s ... chup2.html

Hans-Peter
Hans-Peter

Locked