How to use SketchUp Ruby C/C++ Extension Expenses

Hello, everyone. We’re getting a lot of information about Ruby from this site. Now I’m trying to link Ruby to the dll file. While I was searching, I saw something called SketchUp Ruby C/C++ Extension Expenses, and I downloaded it and looked at the contents of the file, but I’m not sure how to use it. What I want to do is write an UI with VB or C, call it up from the sketch-up, bring the information inside the UI into the SU and model it.
Can you explain how to use it in detail?

Misc info on Ruby C extensions ...

The official example is here …

See the Ruby Resource book list and the PDF book on Extending Ruby …

Such a task is so complex that it does not lend well to teaching via a forum.
You have a large and steep learning curve to navigate. Needing to know C and learn Ruby (which is actually implemented in C/C++,) as well as learning how the SketchUp application works and it’s SKP document object model (which means learning it’s Ruby API.)

However, there are quite a few topic threads on this subject already in these Developer categories. (Use the search feature magnifying glass icon from within this category to find these old threads.)


Note that the C API is not yet “safe” to use to modify a live model object. (It has been first implemented to to operate on files for import / export to other 3rd party applications.)

This means that C extension must currently make Ruby API calls either via Ruby or Ruby’s C core rb_func_call function.

Googling “SketchUp Ruby C/C++ Extension Expenses” finds nothing.

In forum posts, whenever you refer to something “out there in web-land” it is always best to provide a link. Otherwise we cannot know exactly what you need help with.

More info on loading Ruby C extension files ..

This is a specific issue that can be easily answered.

In order for Ruby’s global #require method to load a DLL, the DLL library must have a Ruby compatible C entry point. This entry point is a C function whose name begins with the substring "Init_" and ends with the exact case-sensitive name of the DLL library file (minus the file extension.)

So as an example, if you have the DLL library named "ijs_utils.dll" then it must have an C entry function named "Init_ijs_utils".

This is all explained in the book on extending Ruby and shown in the official “Hello World” example.


And BTW, the DLL must be compiled with the same version of Ruby and version of Visual Studio that your target version of SketchUp uses. This means that your Ruby loader script may need to be version flexible and be supplied with multiple compiled versions of your C DLL file ( … if supporting a range of SketchUp versions.)

The way I want to do this is to bring in the UI written in the dll file from the SU, and use the information entered in the UI from the SU. I’ll find a similar file and upload it. You put the dll and rb files in the Sketchup\Plugins folder, run the sketchup, and run the functions in the menu.
Error: #WIN32OLERUNtimeError: failed to create WIN32OLE object from `SU_Forms.FormHost’
HRESULT error code:0x80040154
Class not registered.
The message says.
I don’t know if the file is wrong or if I’m not good at using it.SU_Forms_VB_NET2008_Project.zip (91.3 KB) testbed.rb (470 Bytes)

I think everyone needs to do a better job of discerning between a *.dll file and an *.so file. One is generic, one is specific to a Ruby ABI version

A *.so file is normally loaded with require, a *.dll is loaded with Fiddle (or an *.so file)

1 Like

@MSP_Greg, right. At one time require could load a library if it had the proper entry point function and the file extension didn’t matter. It may be that this was changed, but the Ruby docs do not seem to have been corrected to explain this.

Okay, now that I’ve looked at the “testbed” script, I see that your DLL is not a Ruby extension per se. Instead it is an OLE class registration library.

As Greg, implies, this would need to be loaded with Ruby’s Fiddle library which will wrap the Windows SDK’s LoadLibrary function.

However, this code is so old that it violates many code standards for a shared coding environment.
“testbed.rb” script is not within a module, defines methods in the global ObjectSpace, refers to a global object which doesn’t do any translation, and doesn’t use a persistent reference for the OLE form object. (The tb reference will go out of scope when the testbed method ends destroying the form window as well.)

Also using the API messagebox is a bad idea for debugging.

Is it “SU_Forms.DLL”` the library that needs to be loaded ?

I now see that this project came from back in the SketchUp v7 days (2009).

We no longer just drop plugins into the “Plugins” folders.

Since that time in the v8 timeframe, a new SketchupExtenstion class was created that can install zip archives (with “RBZ” file xtensions into the correct “plugins” folder in the correct place. The correct place is no longer in the “Program Files” path. With the previous 3 version or so, the “Plugins” folder is now in the user’s AppData path.)

or perhapWIN32OLE_TYPELIB constructor might be “the ticket” ?

Dan,

Actually, I’m wrong. The docs do state that require will check dll’s. See Kernel.require. From 2.2 thru master…

I don’t recall specifically looking for file extension info, but I’ve worked with a lot of extension gems, etc. Never seen a dll built as a Ruby extension…

Lastly, OLE objects are a whole other topic, and obviously Windows specific. I haven’t seen them used a lot. Myself and another person made quite a few changes in the Ruby win32ole tests because MSFT has been removing them from the OS.

Ah, so OLE is a dinosaur ?

I was wondering if the OP’s old Vista era (NT 6.x) OLE libraries would even load under NT 10 ?

So, this may be the proverbial “red herring”.

Thank you for your many answers.
I don’t know much about C language and Ruby yet. I’ll study more and ask you specific questions.
Thank you.

You may just be better off using the UI::HtmlDialog class for your interfaces.